55using Serilog ;
66using System ;
77using System . IO ;
8- using System . Runtime . CompilerServices ;
98using System . Threading . Tasks ;
109using Windows . Storage ;
1110
@@ -27,7 +26,7 @@ public App()
2726
2827 protected override async void OnLaunched ( LaunchActivatedEventArgs args )
2928 {
30- await InitializeLocalizer ( ) ;
29+ await InitializeWinUI3Localizer ( ) ;
3130
3231 this . window = Host . Services . GetRequiredService < MainWindow > ( ) ;
3332 this . window . Activate ( ) ;
@@ -108,34 +107,16 @@ private static IHost BuildHost()
108107 . Build ( ) ;
109108 }
110109
111- /// <summary>
112- /// Creates default Resources.resw files for WinUI3Localizer.
113- /// </summary>
114- private async Task InitializeLocalizer ( )
110+ private static async Task InitializeWinUI3Localizer ( )
115111 {
116112#if IS_NON_PACKAGED
117- // Initialize a "Strings" folder in the executables folder.
118- StringsFolderPath = Path . Combine ( AppContext . BaseDirectory , "Strings" ) ;
119- StorageFolder stringsFolder = await StorageFolder . GetFolderFromPathAsync ( StringsFolderPath ) ;
113+ PrepareEnvironmentForWinUI3LocalizerOnNonPackagedApp ( ) ;
120114#else
121- // Initialize a "Strings" folder in the "LocalFolder" for the packaged app.
122- StorageFolder localFolder = ApplicationData . Current . LocalFolder ;
123- StorageFolder stringsFolder = await localFolder . CreateFolderAsync ( "Strings" , CreationCollisionOption . OpenIfExists ) ;
124- StringsFolderPath = stringsFolder . Path ;
125-
126- // Create string resources file from app resources if doesn't exists.
127- await MakeSureStringResourceFileExists ( stringsFolder , "en-US" , "Resources.resw" ) ;
128- await MakeSureStringResourceFileExists ( stringsFolder , "en-US" , "ErrorMessages.resw" ) ;
129- await MakeSureStringResourceFileExists ( stringsFolder , "es-ES" , "Resources.resw" ) ;
130- await MakeSureStringResourceFileExists ( stringsFolder , "es-ES" , "ErrorMessages.resw" ) ;
131- await MakeSureStringResourceFileExists ( stringsFolder , "ja" , "Resources.resw" ) ;
132- await MakeSureStringResourceFileExists ( stringsFolder , "ja" , "ErrorMessages.resw" ) ;
115+ await PrepareEnvironmentForWinUI3LocalizerOnPackagedApp ( ) ;
133116#endif
134117
135- ILocalizer localizer = await new LocalizerBuilder ( )
136- . AddPriResourcesForLanguageDictionaries ( new [ ] { "en-US" , "es-ES" , "ja" } )
137- . AddPriResourcesForLanguageDictionaries ( new [ ] { "en-US" , "es-ES" , "ja" } , "ErrorMessages" )
138- //.AddStringResourcesFolderForLanguageDictionaries(StringsFolderPath)
118+ _ = await new LocalizerBuilder ( )
119+ . AddStringResourcesFolderForLanguageDictionaries ( StringsFolderPath )
139120 //.SetLogger(Host.Services
140121 // .GetRequiredService<ILoggerFactory>()
141122 // .CreateLogger<Localizer>())
@@ -160,4 +141,27 @@ private async Task InitializeLocalizer()
160141 //}))
161142 . Build ( ) ;
162143 }
163- }
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