Skip to content

yuanmingyi/resxgen

Repository files navigation

ResxGen: Tool for collecting string resources from xaml files and convert between text string resources and resx resources in WPF development

Introduction:

  • ResxGen is a tool which creates easy editing text files for programmers to separate the translation or language work from the coding.
  • With this tool, one can directly write xaml files with resx string represents and get auto generated corresponding resx files. Also the tool will generate a text (.txt) file for easy editing without any coding tools.

Usage:

The binaries contain three files:

stringsutil.py

  • python utility to do collecting of localization strings from WPF xaml files and output to txt files. The target files will be incremental updated.

examples:

  • see help message

    python stringsutil.py -h
  • use lexlocalizeextension, the default dictionary is Strings, and need a zh-CN localization, do conversion to Example.xaml

    python stringsutil.py -c lex -d Strings -l zh-CN Example.xaml
  • use lexlocalizeextension, the default dictionary is Strings, need no localization, do conversion to all xaml files in directory D:\workspace\ResxgenExample:

    python stringsutil.py -c lex -d Strings D:\workspace\ResxgenExample
  • use static resources localization, need zh-CN and en-US localization, do conversion to file Example.xaml and View\Example1.xaml

    python stringsutil.py -c loc -ns loc Example.xaml View\Example1.xaml

    or

    python stringsutil.py -c loc -nsuri "clr-namespace;ResxgenExample.Resources.Strings" Example.xaml View\Example1.xaml
  • add extra blank line between each string

    python stringsutil.py -c lex -d Strings -e D:\workspace\ResxgenExample

resxgen.exe

  • Main executable, convert between text files and resx files. The target files will be overwritten.

examples:

  • see command line arguments

    resxgen.exe
  • Convert the dictionary Project\Strings.txt and the multi-language version to Project\Resources\Strings.resx

    resxgen.exe -outdir Project\Resources Project\Strings.txt
  • Convert the dictionary Project\Strings.txt and Project\Submodule\Localization.txt to Strings.resx and Localization.resx in Project\Resources

    resxgen.exe -outdir Project\Resources Project\Strings Project\Submodule\Localization
  • Convert the dictionary Project\Strings.txt and Project\Strings1.txt to Project\Strings.resx and Project\Strings1.resx

    resxgen.exe -dir Project Strings Strings1
  • Convert Project\Resources\Strings.resx to Project\Resources\Strings.txt, the Strings.txt would be replaced.

    resxgen.exe Project\Resources\Strings.resx -i
  • Convert Project\Resources\Strings.resx to Project\Text\Strings.txt, add extra blank line between strings

    resxgen.exe -i Project\Resources\Strings.resx -c -o Project\Text

Template.resx

  • the resx template generated by any version of VisualStudio, used by resxgen.exe.

Tutorial

First time:

  • Create and edit WPF xaml files using Resx file for the text in UI. In xaml file write code as below (using the WPFLocalizationExtension):
<UserControl x:Class="Resxgen.Examples.Xaml.LexSample"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:lex="http://wpflocalizeextension.codeplex.com"
             lex:ResxLocalizationProvider.DefaultDictionary="Strings"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock Text="{lex:Loc LexTextBlockText}" />
    </Grid>
</UserControl>
  • LexLsave it as example\xaml\LexSample.xaml, for example.

  • run python stringsutil.py -o examples\text -c lex -l zh-CN,en-US examples\xaml\LexSample.xaml will generate Strings.txt, Strings.zh-CN.txt and Strings.en-US.txt in the examples\xaml and the file will be like:

## Auto-generated by stringsutil.py at 2019-12-16 13:36:13.007000

LexTextBlockText=
  • edit Strings.txt (also zh-CN, en-US version) as below and save:

## Auto-generated by stringsutil.py at 2019-12-16 13:36:13.007000

LexTextBlockText=Hello world
  • run resxgen.exe -outdir examples\resx examples\text\Strings.txt then Strings.txt, Strings.zh-CN.txt and Strings.en-US.txt with localized strings will be generated in the examples\resx

Incrementally edit strings

  • Now add examples\xaml\StaticSample.xaml to project:
<UserControl x:Class="Resxgen.Examples.Xaml.StaticSample"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:loc="clr-namespace:Resxgen.Resources"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock Text="{x:Static loc:Strings.StaticTextBlockText}" />
    </Grid>
</UserControl>
  • run python stringsutil.py -c loc -n loc examples\xaml\StaticSample.xaml -o examples\text
  • Then the Strings.txt, Strings.zh-CN.txt and Strings.en-US.txt will be updated as:
## Auto-generated by stringsutil.py at 2019-12-16 13:36:13.007000

LexTextBlockText=Hello world

## Auto-generated by stringsutil.py at 2019-12-16 13:46:15.001000

StaticTextBlockText=

There are already edited .resx files, need to involve this tool

  • first convert the resx files to text files:
  • keeps the Strings.*.resx files and remove all the text files in examples\text, then run: resxgen.exe -i -dir examples\resx Strings -outdir examples\text
  • Strings.txt, Strings.zh-CN.txt, Strings.en-US.txt will be generated with the localization strings converted as:
## Auto-generated by stringsutil.py at 2019-12-16 13:36:13.007000

LexTextBlockText=Hello world

## Auto-generated by stringsutil.py at 2019-12-16 13:46:15.001000

StaticTextBlockText=Static Block!
  • Then do as the prior tutorial ask to add more localization strings

About

Tool for collecting string resources from xaml files and convert between text string resources and resx resources in WPF development

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published