[MonoDevelop] How Do I...? Localize Messages via Resources and Embedding them Using MonoDevelop
Tomasz Kubacki
tomasz.kubacki at gmail.com
Thu Jul 7 02:14:49 EDT 2011
> *My problem is this*: Using MonoDevelop (which is the preferred environment
> for a number of projects I'm working on) I'm trying to figure out how to use
> resource files for localizing messages, as well as how to properly include
> them in the project as an embedded resource.
>
> My goal is to have a resources file with simple name-value pairs for message
> keys and their values, and have separate files for their localized strings
> e.g.
hi,
if you use linux/mono exclusively you can just use po files not resx
(create example gtk-sharp app and see how it's done in autogenerated
fies), however if you want your app to be to be cross platform you
should use resx files.
AFAIR there is no resource editor for MD but you can covert po files into resx.
There are plenty of handy po editors (e.g poeditor)
What you probably should do is:
1. Generate po file from your sources with xgettext
e.g below command will generate translation.po from source and add
entries for each Translate.GetString occurance:
xgettext -L C# --no-wrap --keyword='Translate.GetString('
--from-code=UTF-8 sourceFile -o transaltions.po
2. Translate po file with po editor
now you will have two po files:
translation.po and e.g translation.de.po
3. convert po into resx file
e.g.
resgen2 translation.po YourAssemblyName.resx
resgen2 translation.de.po YourAssemblyName.de.resx
[...]
4. Add YourAssemblyName.resx to project and mark it's build action as
'Embed as Resource'
Add YourAssemblyName.de.resx and mark it's build as 'Embed as Resource'
Now using resource manager is twoliner:
ResourceManager resmgr = new ResourceManager(FULL_ASSEMBLY_NAME,
Assembly.GetExecutingAssembly());
resmgr.GetString(string_to_stranslate);
hope it helps.
Cheers,
Tomasz Kubacki
More information about the Monodevelop-list
mailing list