Compare Xamarin.Android CPL localization techniques (.xml .po .mo .resx .xlf) - c#

I have inherited an Xamarin Crossplatform project, (Android only,) that had a 'strings.xml' file with some button-names in it.
Need to find a way to add more languages easily and convert code-strings to translatable too (>300+), not just component-Texts.
I've tried many things so far, but nothing worked as expected: [*]
( Most of the examples and help are for Xamarin.Forms only. )
1.) installed ResX manager
it did not recognized my XML files
created .resx files manually, but those have nothing to do with existing xml-translations
could not get back those texts from C# code I've inserted at the manager window
2.) created a second strings.xml >> placed into values-hu folder >> copied XML content >> translated inside the XML.
It works only for buttons in the IDE placed into the activity
can NOT get text with GetText(...,...) from my C# code because it needs an (int)...I don't know how to generate and pair with my own constants
Resources.Strings... does not pop up any of my own string either
whenever I try to add a new element at the IDE,
I have to search and copy manually the new lines to each XML one by one
there is no "translator window" for them like ResX
can not group strings inside the XML file
3.) installed Multilingual App Toolkit 4.0
seems to be just a different file format than .resx, but same problems
complained about not connected to Azure
offered me a "new english" translation from my original english XML
could not add NEW lines, etc.
4.) installed POEdit + Nuget>GetText
at first sight this seemed to be the perfect solution, but
PoEdit has found only 4 strings in my .cs files
( preferences' I/O strings with GetText() method to read from my config.xml )
could not import string.xml files to translate for 3. lang.
do not understand the .po > .mo conversion concept
installed the nuGet GetText > but no new sub-menu appeared anywhere inside VS.
5.) upgraded to VS2017
6.) asked on a local forum, but nobody answered.
7.) Searched through ca 100 topics here >> ... most of them are about Xamarin Forms ... but those seems to be invalid for droid.
[*] by expected I've imagined having a simple wizard where I can:
go through each string in my *.cs files, where I can give a constant name and it's converting "Really Exit" > to: _tr(Res.Main.really_exit)
or mark to skip
should have a manager to easy translate (like ResX), or ADD new lines!
having both component-texts and code-string inside ONE(/ language?) file
possibly group strings by activity / logic. (So translators can see where is what)
... but nothing seems to be able to handle strings.xml files and .cs file-string all in one easily.
So... Now I am totally confused. I've spent a whole week to see some kind of "order" in this chaos, but could not find a proper writing that explains, WHAT METHOD should someone use to do things easily for droid translation and why? Thank you!

I would go with your second approach because it uses the Android build-in localization system. A benefit of using it is that it already has a fallback-solution included, if a language or a key for one language could not be found.
You can use it in your layout files:
<Button
android:text="#string/LogOn_Login"
or inside code:
var progressDialog = new ProgressDialog(this);
progressDialog.Indeterminate = true;
progressDialog.SetCancelable(false);
progressDialog.SetMessage(GetString(Resource.String.LogOn_ProgressMessage));
But you need to know the difference between an Activity and a Fragment.
In an Activity you just need to call GetString(). Which requires an int, that you get from Resource.String.YOUR_KEY. But in a Fragment you have to give the context. The call changes to Activity.GetString().
New languages or strings can easily added. I usually add new string to the strings.xml inside values-folder first. That way I make sure I have the fallback ready. A new string has the following semantics:
<string name="KEY">VALUE</string>
Filled with real data:
<string name="LogOn_ProgressMessage">Authenticating...</string>
After saving the strings.xml file, it turns out to be good to rebuild the project to make sure the Resource.designer.cs is updated. I sometimes saw the behavior that otherwise my newly added keys where not accessible with Resource.Strings.
When it comes to editing the strings.xml, I am with you that there is no "translator window" and that you have to copy each new key to all supported languages. To overcome this issue we build us a tool that creates all those files for use on every build. This way we support a quite large app with more than 21 languages.

With Xamarin I would go down the .Resx files route. string.xml files are an Android solution and don't fit very well into the .NET world.
How to localize your code is nicely explained here:
https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/
And with Reshaper you can extract all the strings from your code:
https://www.jetbrains.com/resharper/features/internationalization.html
Yes, you will have to convert your XML files. In what format are they? You might be able to use this tool:
http://converter.webtranslateit.com/
To use .NET Resource files inside your Library, you have to add the resources to your project first and configure them like below:
Now you can use them for example like this:
BillManagement.ResourceManager.GetString("TaxSetupWrong")
Or
LibraryName.Resources.BillManagement.TaxSetupWrong

Related

Cannot create resx file for i18n

Still spinning up on Xamarin.Forms and C#.
Did some research and everything is telling me that to create my externalized strings file, I just right click on the directory, click New Item... then click on Resource file. The problem is that my list looks vastly different than the lists I'm seeing in the tutorials and doesn't include a Resource file. Here's my list:
So I'm not sure what to click to get a resource file. There's evidently some special stuff about it because I tried creating an empty file and naming it that and it was confused.
How do I create these i18n resource files in Xamarin?
Thanks.
As suggested by #Deczaloth, I added the C# desktop applications workload and that made the resources file available. Yet another fail from Microsoft.

C#.NET & Translation of external component

I'm maintaining one program written in C# 2.0 (VS2005). It has pretty large codebase, lot of authors, it is almost internal app, but currently it is also one of our customers using it.
App is multilingual and translation of own forms and components works OK. But, there is one component - DockPanel Suite by WeifenLuo and I need to translate it to another language (zh-CN) - one of the chinese guys translated resource file to his language and now I'm trying to include and use in application, but I'm failing in it - although whole app is in chinese, this component remains in english. The untranslated resource file can be found on github: https://github.com/dockpanelsuite/dockpanelsuite/blob/master/WinFormsUI/Docking/Strings.resx
How to do that? I tried almost everything, naive approach (just resgen and compile by al, and trying to use it as satellite assembly - also tried ilmerge), then opening DockPanelSuite in VS2013 Express, adding resx as Strings.zh-CN.resx, but nothing works and tooltips and others are still in english.
Tried also stepping-in with debugger, but debugger broke at tooltip = Strings.DockPaneCaption_ToolTipAutoHide but it didn't step into getter defined in Strings.Designer.cs
I'm stuck and I don't know, how to do that. Any idea? Thanks very much!
I was able to translate a label in the demo application in a very simple process:
git clone the library
Copy & paste the Strings.resx file
Rename the copy into Strings.pt-BR.resx
Compile, it's done (in my case, I translated the "Close" label)
however, this project contains many Strings.resx files
Did you change all of them? Or did you just change one? (maybe a wrong one, like I did in my first try)

custom client localization form Win Forms

I have big WinForms project,and now i need to create module,where client can create/update/delete its own localization to a project (dataGrid Name-Value,like resx files).Also we need a default localization.But in WinForms every form has own resx file=( What the best way to realize this feature?Xml file or it could be done by resx files.
In previous version of the project (unfortunately no source code) it was jsut text Key-Value file.
There are diffrent way to approch that topic. On top of my head i have 2 solutions for that problem.
First solution
Since *.resx files are compiled into executable you cannot really modify them, but since you are using them already easiest approach would be to change reference from original build in *.resx file to one you have made and put in your folder hierarchy. That way you could use your build in files as default and search for other languages if they exists replace them.
This might help you Modifying .resx file in c#
Downside of this approach is that resx files are c# classes and could be realy hard to edit outside of Visual Studio editor.
Second solution
If you have time to move all of your default texts to *.xml files you could do that and use similar approach like in *.resx file. Since i found it easier to create and edit xml files this could save your day. Downside of that approach is time required to connect every string to your windows forms app.

End user wants to add languages dynamically to his website

We have to build an event registration website for our client in ASP.NET using C#.
One of the requirements is that the client wants to add new foreign languages to his website himself using en excel file. I know how to make a website multilingual in Visual Studio, but I have no idea how to generate a resource file based on an excel file in code.
I also noticed VS generates a second file called Resource.en.designer.cs but I can't find any documentation how to generate that file either.
btw, the enduser is anything but IT-related. He knows his way around excel though (obviously).
Any help is appreciated!
Yoeri
EDIT:
!Robert Levy Provided a good method!
HOW TO:
STEP 1:
Read the excel file (using an OleDBAdapter was the best method for me, as you can use column headers etc)
Write the language to a txt file in this format:
KEY=TRANSLATION
no spaces or anything else
STEP 2:
Locate ResGen.exe on your computer (it comes with Visual Studio, so look somewhere like c:\program files\visual studio\sdk... however I found it # C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe)
STEP 3:
Invoke the exe with Process.Start("resgen.exe")
hint: use ProcesStartInfo for easy argument and preferences settings
(STEP 4:)
Move the file to your desired location (I find the App_GlobalResources works perfectly)
STEP 5:
Set the user currentUIculture to your desired culture!
ResGen.exe will compile resource files for you. You could either get him to deliver text files in the format used by that tool or write your own code that extracts from excel to generate the text files. Then just invoke this EXE and deploy your newly generated resource DLL. I am assuming you already know how to read things from resource files and use the appropriate one based on user preference.
http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx
This is probably one place where you would like to use resources from database rather than simple resx files. It would be easier just to populate database table(s) with Excel data than transforming it to standard resx file (it could be a problem in the future if MS decided to modify file format).
So I would suggest you to write your own ResourceReader which would load strings from database (it could load it directly from Excel as well, but for many reasons I wouldn't recommend this method).
You should ask your end-user if they really have to get another language 'on the fly' and how many languages they expect they are going to add.
Otherwise, e-mailing the Excel file to you and manually creating the resource file might be by far the cheapest solution....

C#: Resource file refactoring

Does anyone know of a good tool for refactoring resources in a visual studio 2008 solution?
We have a number of resource files with translated text in an assembly used for localizing our application. But they have gotten a bit messy... I would like to rename some of the keys, and move some of them into other resource files. And I would like those changes be done in my code, and the translated versions of the resource files as well. Maybe a some analysis on what strings are missing in the translated versions, and what strings have been removed from the original as well...
Does anyone know of a good visual studio extension or ReSharper plugin that can help me with this? Right now it is kind of a pain, because I have to first rename the key in the base resource file, then in the localized versions. And then compile to get all the compile errors resulting from the key which now have a different name, and then go through and fix them all... very annoying =/
I just stumbled across this question which prompted me to blog about what I use for this problem here Moving and renaming resource keys in a .resx file.
I have two PowerShell scripts, one which renames a resource key and one which moves a resource key from one resource file to another.
Using these scripts I am able to rename a resource key:
.\RenameResource.ps1 oldKey newKey
And I can move a resource with key “keyName” from a file named “ResourceFile1.resx” to “ResourceFile2.resx”:
.\MoveResource.ps1 ResourceFile1 ResourceFile2 keyName
RGreatEx is suitable when you need to move a lot of strings in code to resources. But in this case it can't help.
There are no such plugin (*this means that I have never seen such and didn't found in google, but there are some localizators which can help to translate to new language - http://www.peoplewords.com/download/ResxEditor.aspx and http://sourceforge.net/projects/resx/ and http://www.resx-localization-studio.net/ and http://madskristensen.net/post/A-NET-resource-editor-application-for-resx-files.aspx). But you easily (may be) can do this without it.
All you need is to write some small tool which will generate common dictionary of strings for a selected language for several selected resx files and store it somewhere. Another tool you need to create is a tool which will generate new resx files (after your changes) using changed resxs as templates and using the dictionary generated by previous tool.
Of course all new and changed strings will be missing but this can be fixed manually. This will take not so much time (especially when you'll add functionality to write a log of missing strings during generation new resx) .
Were looking into Sisulizer to localize our software, and I think it accomplishes what you're asking for (a bit overkill perhaps?)
Seems to be some new features in ReSharper 5 that helps with this
Localizing your Applications with ReSharper 5
This demo shows how ReSharper 5 helps you make strings in your code localizable quickly, without breaking your regular workflow. Working with resource files is no more a developer's nightmare with ReSharper 5.

Categories

Resources