@@ -26,7 +26,7 @@ public App()
26
26
27
27
protected override async void OnLaunched ( LaunchActivatedEventArgs args )
28
28
{
29
- await InitializeLocalizer ( ) ;
29
+ await InitializeWinUI3Localizer ( ) ;
30
30
31
31
this . window = Host . Services . GetRequiredService < MainWindow > ( ) ;
32
32
this . window . Activate ( ) ;
@@ -107,34 +107,16 @@ private static IHost BuildHost()
107
107
. Build ( ) ;
108
108
}
109
109
110
- /// <summary>
111
- /// Creates default Resources.resw files for WinUI3Localizer.
112
- /// </summary>
113
- private async Task InitializeLocalizer ( )
110
+ private static async Task InitializeWinUI3Localizer ( )
114
111
{
115
112
#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 ( ) ;
119
114
#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 ( ) ;
132
116
#endif
133
117
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 )
138
120
//.SetLogger(Host.Services
139
121
// .GetRequiredService<ILoggerFactory>()
140
122
// .CreateLogger<Localizer>())
@@ -159,4 +141,27 @@ private async Task InitializeLocalizer()
159
141
//}))
160
142
. Build ( ) ;
161
143
}
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