@@ -26,7 +26,7 @@ public App()
2626
2727 protected override async void OnLaunched ( LaunchActivatedEventArgs args )
2828 {
29- await InitializeLocalizer ( ) ;
29+ await InitializeWinUI3Localizer ( ) ;
3030
3131 this . window = Host . Services . GetRequiredService < MainWindow > ( ) ;
3232 this . window . Activate ( ) ;
@@ -107,34 +107,16 @@ private static IHost BuildHost()
107107 . Build ( ) ;
108108 }
109109
110- /// <summary>
111- /// Creates default Resources.resw files for WinUI3Localizer.
112- /// </summary>
113- private async Task InitializeLocalizer ( )
110+ private static async Task InitializeWinUI3Localizer ( )
114111 {
115112#if IS_NON_PACKAGED
116- // Initialize a "Strings" folder in the executables folder.
117- StringsFolderPath = Path . Combine ( AppContext . BaseDirectory , "Strings" ) ;
118- StorageFolder stringsFolder = await StorageFolder . GetFolderFromPathAsync ( StringsFolderPath ) ;
113+ PrepareEnvironmentForWinUI3LocalizerOnNonPackagedApp ( ) ;
119114#else
120- // Initialize a "Strings" folder in the "LocalFolder" for the packaged app.
121- StorageFolder localFolder = ApplicationData . Current . LocalFolder ;
122- StorageFolder stringsFolder = await localFolder . CreateFolderAsync ( "Strings" , CreationCollisionOption . OpenIfExists ) ;
123- StringsFolderPath = stringsFolder . Path ;
124-
125- // Create string resources file from app resources if doesn't exists.
126- await MakeSureStringResourceFileExists ( stringsFolder , "en-US" , "Resources.resw" ) ;
127- await MakeSureStringResourceFileExists ( stringsFolder , "en-US" , "ErrorMessages.resw" ) ;
128- await MakeSureStringResourceFileExists ( stringsFolder , "es-ES" , "Resources.resw" ) ;
129- await MakeSureStringResourceFileExists ( stringsFolder , "es-ES" , "ErrorMessages.resw" ) ;
130- await MakeSureStringResourceFileExists ( stringsFolder , "ja" , "Resources.resw" ) ;
131- await MakeSureStringResourceFileExists ( stringsFolder , "ja" , "ErrorMessages.resw" ) ;
115+ await PrepareEnvironmentForWinUI3LocalizerOnPackagedApp ( ) ;
132116#endif
133117
134- ILocalizer localizer = await new LocalizerBuilder ( )
135- . AddPriResourcesForLanguageDictionaries ( new [ ] { "en-US" , "es-ES" , "ja" } )
136- . AddPriResourcesForLanguageDictionaries ( new [ ] { "en-US" , "es-ES" , "ja" } , "ErrorMessages" )
137- //.AddStringResourcesFolderForLanguageDictionaries(StringsFolderPath)
118+ _ = await new LocalizerBuilder ( )
119+ . AddStringResourcesFolderForLanguageDictionaries ( StringsFolderPath )
138120 //.SetLogger(Host.Services
139121 // .GetRequiredService<ILoggerFactory>()
140122 // .CreateLogger<Localizer>())
@@ -159,4 +141,27 @@ private async Task InitializeLocalizer()
159141 //}))
160142 . Build ( ) ;
161143 }
162- }
144+ #if IS_NON_PACKAGED
145+ private static void PrepareEnvironmentForWinUI3LocalizerOnNonPackagedApp ( )
146+ {
147+ // Initialize a "Strings" folder in the executables folder.
148+ StringsFolderPath = Path . Combine ( AppContext . BaseDirectory , "Strings" ) ;
149+ }
150+ #else
151+ private static async Task PrepareEnvironmentForWinUI3LocalizerOnPackagedApp ( )
152+ {
153+ // Initialize a "Strings" folder in the "LocalFolder" for the packaged app.
154+ StorageFolder localFolder = ApplicationData . Current . LocalFolder ;
155+ StorageFolder stringsFolder = await localFolder . CreateFolderAsync ( "Strings" , CreationCollisionOption . OpenIfExists ) ;
156+ StringsFolderPath = stringsFolder . Path ;
157+
158+ // Create string resources file from app resources if doesn't exists.
159+ await MakeSureStringResourceFileExists ( stringsFolder , "en-US" , "Resources.resw" ) ;
160+ await MakeSureStringResourceFileExists ( stringsFolder , "en-US" , "ErrorMessages.resw" ) ;
161+ await MakeSureStringResourceFileExists ( stringsFolder , "es-ES" , "Resources.resw" ) ;
162+ await MakeSureStringResourceFileExists ( stringsFolder , "es-ES" , "ErrorMessages.resw" ) ;
163+ await MakeSureStringResourceFileExists ( stringsFolder , "ja" , "Resources.resw" ) ;
164+ await MakeSureStringResourceFileExists ( stringsFolder , "ja" , "ErrorMessages.resw" ) ;
165+ }
166+ #endif
167+ }
0 commit comments