tesar-tech / ResourceExtractor

Generate Resources.resw file by extracting strings from .xaml and .cs files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resource Extractor

Keep your strings of primary language in xaml. Extract them by running this script.

How to use it

  1. Edit resourceExtractor.fsx to match folder of your project and path to Resource.resw file. Create folder Strings\en-US if not exits.

    let folderToDeepSearchForFiles = __SOURCE_DIRECTORY__  + @"\ResourceExtractorSampleApp\ResourceExtractorSampleApp"
    let finalResourceFilePath =  folderToDeepSearchForFiles + @"\Strings\en-US\Resources.resw"
  2. Respect some necessary conventions:

    • Place properties, that you want to extract, after the x:Uid property. Last character of the x: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`
  3. Run F# script. Note that existing en-US\Resource.resw file will be overwritten.For complete example, see sample UWP app.

The flow with Multilingual app toolkit

Start with instalation of Multilingual app toolkit extension and Multilingual app toolkit Editor

  1. Write your xaml with x:Uid (follow instructions above)
  2. Run resourceExtractor.fsx script. This will generate en-US\Resource.resw.
  3. Build your app. This will generate xlf files under MultilingualResources folder.
  4. Use Multilingual app toolkit Editor to translate your strings.
  5. Build app again. It will generate translated Resource.resw files.

Custom Accelerators

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.

Limitations

  • There are only two possible outputs:
    • Rewritten en-US\Resource.resw file.
    • Error in terminal.
  • 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)

Contributing

If you have any idea how to make script or sample app better, feel free to submit issue or pull-request.

About

Generate Resources.resw file by extracting strings from .xaml and .cs files.


Languages

Language:C# 57.2%Language:F# 42.8%