Keep your strings of primary language in xaml. Extract them by running this script.
-
Edit
resourceExtractor.fsxto match folder of your project and path toResource.reswfile. Create folderStrings\en-USif not exits.let folderToDeepSearchForFiles = __SOURCE_DIRECTORY__ + @"\ResourceExtractorSampleApp\ResourceExtractorSampleApp" let finalResourceFilePath = folderToDeepSearchForFiles + @"\Strings\en-US\Resources.resw"
-
Respect some necessary conventions:
- Place properties, that you want to extract, after the
x:Uidproperty. Last character of thex:Uidmatches number of subsequent properties to be extracted. If last character is not a number, only one subsequent property will be taken.
- For extracting resources from .cs files use
ReousrceLoader. "TextFromCSharpCode" string will be taken as resource name and comment as default value:
ResourceLoader.GetForCurrentView().GetString("TextFromCSharpCode");//This default text is placed in comment in MainPage.xaml.cs`
- Place properties, that you want to extract, after the
-
Run F# script. Note that existing
en-US\Resource.reswfile will be overwritten.For complete example, see sample UWP app.
Start with instalation of Multilingual app toolkit extension and Multilingual app toolkit Editor
- Write your xaml with
x:Uid(follow instructions above) - Run
resourceExtractor.fsxscript. This will generateen-US\Resource.resw. - Build your app. This will generate
xlffiles underMultilingualResourcesfolder. - Use Multilingual app toolkit Editor to translate your strings.
- Build app again. It will generate translated
Resource.reswfiles.
It also works with custom accelerators definitions:
var acceleratorsList = new List<(string identity, string label, VirtualKey key, VirtualKeyModifiers modifiers)>()
{
//ResourceExtractorAcceleratorsStart
("OpenFile","Open File",VirtualKey.O,VirtualKeyModifiers.Control),
("HelpAndFeedback","Help And Feedback",VirtualKey.F1,VirtualKeyModifiers.None),
("Settings","Settings",VirtualKey.S,VirtualKeyModifiers.Shift),
//ResourceExtractorAcceleratorsEnd
};The comments (//ResourceExtractorAcceleratorsStart and //ResourceExtractorAcceleratorsEnd) are the key here -> script will look for these comments and extract strings inside them.
- There are only two possible outputs:
- Rewritten
en-US\Resource.reswfile. - Error in terminal.
- Rewritten
- Script does not create folder structure for you (
Strings\en-US\). en-US\Resource.reswcreated by script is not automatically included in UWP project (you need to include it in project just once)
If you have any idea how to make script or sample app better, feel free to submit issue or pull-request.

