Keep your strings of primary language in xaml. Extract them by running this script.
-
Edit
resourceExtractor.fsx
to match folder of your project and path toResource.resw
file. Create folderStrings\en-US
if 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:Uid
property. Last character of thex:Uid
matches 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.resw
file 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.fsx
script. This will generateen-US\Resource.resw
. - Build your app. This will generate
xlf
files underMultilingualResources
folder. - Use Multilingual app toolkit Editor to translate your strings.
- Build app again. It will generate translated
Resource.resw
files.
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.resw
file. - Error in terminal.
- Rewritten
- Script does not create folder structure for you (
Strings\en-US\
). en-US\Resource.resw
created 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.