How to implement Android l10n ? - android

How to implement Android system l10n ?It has been l10n in German.What is different between Android and Linux in realizing system localization?
What is Operational process of implementing Android l10n ?
What is needed to implement Android system localization? such as Unicode UTF8, charset,other anything else?

Are you asking about internationalization/localization? If so there's a pretty extensive writeup in the docs.

Localization in Android is a native function, what you have to understand is how to "tell android" where to pick the words translated based on the Language that is set on the device that is running your application.
1. When developing an application for Android avoid "hardcoding" the string values and always use the strings.xml file located in the res/values folder. In that file enter every string used in your application using the tag:
<string name="app_title">Super App</string>
2. From the java side use this string resources from anywhere with the method getString(), this method receives as parameter the id of the item you want to get:
getString(R.string.app_title)
3. Once you have defined every string your app will use, just copy the strings.xml file and paste it in a new folder at the same level of the res/values folder but name it according to the new language you want to add (Read this)
4. Finally, translate every string in each folder to the proper language but keeping the same ids of every string, just changing its content:
res/values-EN/strings.xml
<string name="app_title">Best Application Ever!</string>
res/values-ES/strings.xml
<string name="app_title">La Mejor Aplicación!</string>
res/values-FR/strings.xml
<string name="app_title">Meilleure Application Jamais!</string>

Related

Why my android studio doesn't support typing tamil language?

I am new to android studio. I am trying to create an application with localisation(Tamil). When I paste my Tamil language into android editor the font is not appearing as it should. Here is the Screen shot of my android studio
Already surfed lot here. There is no answer for this issue. It would be great if anyone help on this.
When i tried to generate that same condition I came to know that you haven't added that string named "app" in your default locale i.e. in strings.xml and you are directly trying to add a translation for it.
When u hover to that error it states:
app is transalted here but not found in default locale.
First add(create) that string in your strings.xml file and then try to add it in your strings.xml (tamil) file.
Follow these steps:
First go to your project's res folder --> then open values folder --> then open "strings.xml" file and remove all text inside it and paste the text shown below:
<resources>
<string name="app_name">My Application</string>
<string name="tamil_app_name">ஆங்கில தட்டச்சு வழியாக நம் மொழி</string>
</resources>
Because you have to create a Tamil language string file to set your language. please do the following steps-:
1) Firstly declare all the strings in main strings.xml
2) Then create the string file according to your language choice, Example strings.xml(ta)
3) (ta) is the language code accordingly.
4) The Strings that you have in your main string file convert them into particular language which you want then paste it into the new created String file.

Android Studio string hello_world not present in string.xml file

I'm new to Android app development, trying to follow an intro book on the subject. After creating a blank project, I'm instructed to open the string.xml file, which is supposed to contained the element <string name="hello_world">Hello World!</string> in order to edit the default text of the TextView object. However, the file doesn't contain this element. It only contains:
Also, the book only shows an activity_main.xml layout file, whereas I'm seeing both an activity_main.xml and a content_main.xml file.
Perhaps this is a version issue? My install of the Android SDK is on Windows 10 with the latest API 23, whereas I think the book was published before API 23 was released.
The default project template has probably changed since the book was written.
Try creating a new project, and when asked, choose "Empty Activity" instead of "Blank Activity". This should only include activity_main.xml
This doesn't include the hello_world string in the resources however, so just add it yourself by adding a line with
<string name="hello_world">Hello World!</string>
to the strings.xml
Moreover, they decided to break the convention they had been going with for the default template. There is a TextView in the activity_main.xml layout, but it uses a hardcoded string, rather than a string resource.
If you modify the text attribute of this TextView to: #string/hello_world, you should be able to mirror the desired behavior that the book is asking for.
Here's a page straight out from the official Android docs on String resources. It may help you understand it better: https://developer.android.com/guide/topics/resources/string-resource.html

How to import/export Android string resource to Excel for localization?

I use Android Studio in app development. I want to translate strings by exporting/importing the Android language resources (strings.xml) to Excel file (xlsx). What is the best way to do it?
If anyone else needed the answer,
from res -> strings -> right click-> Open Translations Editor. Select data/variable you need then copy and paste data from Translations Editor to excel . done.
Since CTRL+A not working now in the android studio.
There is one way to convert the android strings file to CSV and then translate it with the help of google translator and then again convert back to XML.
https://www.skydevelopers.net/blog/2-best-ways-to-translate-the-android-strings-file/
here is a blog in detail
Export Strings resource file to csv
Get its content translated(probably from google translate)
convert back the Translated file to Strings.xml(android string resource file)
I used http://convertcsv.com/csv-to-xml.htm this website for converting csv file to strings resource file
need to mention Custom output template to convert it to strings resource file
<string name="{f1}">{f2}</string>
put this in template section provided
website also displays the desired converted output file
As many others pointed out, pressing Ctrl+A in the Translations Editor doesn't work since Android Studio 3.2
I work for a company that outsources translations constantly, so we need to convert android strings to and from xls files.
The only solution that worked for us reliably is this fork of the older android-lang-tool. Just build with maven and run the jar.
It exports strings, string-arrays, plurals and their key-values to an xls file. It even exports the comments.
I would suggest the best tool for android app string localization is the Translations Editor that is inbuilt into Android Studio.
The reason this is a great approach is you are able to make the process both easier for translators and less prone to errors. The XML string files in Android Studio support XLIFF notations that are a standardized method to aid string localization.
By utilizing XLIFF notation in your XML string files you can do the following to help the translators:
Provide additional context for declared strings
Mark message parts that should not be translated
To use XLIFF in your Android string XML files you need to include the XLIFF 1.2 namespace:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
Here are a few examples of strings from the android localization documentation:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Example placeholder for a special unicode symbol -->
<string name="star_rating">Check out our 5
<xliff:g id="star">\u2605</xliff:g>
</string>
<!-- Example placeholder for a for a URL -->
<string name="app_homeurl">
Visit us at <xliff:g id="application_homepage">http://my/app/home.html</xliff:g>
</string>
<!-- Example placeholder for a name -->
<string name="prod_name">
Learn more at <xliff:g id="prod_gamegroup">Game Group</xliff:g>
</string>
<!-- Example placeholder for a literal -->
<string name="promo_message">
Please use the "<xliff:g id="promotion_code">ABCDEFG</xliff:g>” to get a discount.
</string>
</resources>
To access the Translations Editor in Android Studio, select Open Translations Editor from the context menu for your XML string file (ie. strings.xml) in your project tree (see below).
Convert your strings.xml to csv xml-to-csv
Import to Google Sheets
Translate using the formula =GOOGLETRANSLATE(B2, "auto", "de")
Generate output in another column using =CONCATENATE("<string name=",char(34),A2,char(34),">",C2,"</string>") where A2 is the resource_ID and C2 is the translated string
Copy the whole output column and paste inside the <resource>...</resource> tag
As Saad Mahmud answered, you can copy from the translation editor (ctrl+a ctrl+c) and then paste into a spreadsheet.
You can copy it back from a spreadsheet to the translation editor by only copying the "default value" and other languages columns, click on the topmost default value and paste (ctrl+v).
It also works with subsets (both subsets of rows and columns), as long as they are next to each other.
Be aware that empty cells in the spreadsheet will not blank out the translation in the editor, it will leave the current untouched.
Also be careful that you haven't added or removed any translation keys since the spreadsheet was created...
Export or copy to excel only supported in Windows PC.
Still not yet in MAC
As many others pointed out, you can't simply copy and paste translations from and into Translations Editor since Android Studio 3.2.
The simplest solution I found was saving the Excel file with translations as CSV file and then converting it to XML with regex and vice versa.
To "import" translations the steps:
Save xls/xlsx file with key in first column and translation in second column as CSV file (If you have file with non-ANSI caracters use Google sheets, because Excel doesn't support saving in CSV using utf-8)
Open csv file in text editor which supports "find and replace" with regex (eg. Notepad++)
Open "find and replace" and set regex search
Search ^([^,]*),(.*)$ and replace it with <string name="$1">$2</string>
Copy file to string resources file between tag
Fix possible mistakes
You can use similar method in reverse for "export". Use <string.+name="(.*)".*>(.*)</string> for finding and $1,$2 for replacing. But it only works if every string tag in in one line.
NOTE: If your res folder doesn't contians strings.xml then Android Studio won't show "Open Editor" in top right corner of the strings.xml file(Open the file). In my case all my string res files are named like strings_feature.xml
To copy/paste from Translations Editor use Android Studio 3.2 Version and below. It allows copy/paste of full column.

pseudo-resources (using configuraton qualifiers) at runtime

I am creating an app which utilizes images from local device folders (brought back from server) at runtime rather than from the app's own resources folders.
I would like to take advantage of Android's runtime ability to use the appropriate resource files for different display types/orientation, similar to its present runtime usage of different resource folders (ldpi, hdpi, sw600sp etc) but in my case, not actually with complete resource folder content present during the app build.
Which would be the preferred methodology to achieve this?
i) pulling back the server images files and creating a sub-directory structure recognized by Android in a similar fashion as it presently recognizes its res directory structure -- i.e. a runtime pseudo-resource folder if you like.
ii) overriding events to catch orientation changes on existing activities and manually determining display type at start-up, in order to point all the app's activities to appropriate (locally stored at runtime) image files.
I am not entirely sure how to achieve either of the above, hence any indication of preference and general approach would be appreciated.
You can use Android's resource identification mechanism for this too. You can create the different images on your server and you can store the links to this in your strings.xml
So you will have different strings.xml in different res/values-xx folders (where xx stands for the configuration qualifiers). Take a look at Providing Resources to know more about the configuration qualifiers.
so in values-ldpi, your strings.xml can have a value as:
<string name="icon">http://my-server/images/icon-ldpi.jpg</string>
whereas the strings.xml in values-hdpi will have the value as:
<string name="icon">http://my-server/images/icon-hdpi.jpg</string>
and so on.
Edit:
In case the url contains runtime parameters, you can specify the same in the strings.xml as:
<string name="icon">http://my-server/%1$s/images/icon-ldpi.jpg</string>
And you use the same in the Java code as follows:
String iconURL = getResources().getString(R.string.icon, siteId);
If the siteID is 001, depending on the device type, the imageURL would be "http://my-server/001/images/icon-ldpi.jpg" or "http://my-server/001/images/icon-mdpi.jpg" or "http://my-server/001/images/icon-hdpi.jpg" or ... And the fact is that you don't have to do anything in your code to determine the display attributes for this to work.
This has turned out to be easier than I thought. I can just return 'identifier' strings stored in assorted values-xxx folders in order to build an appropriate set of possible file names.
e.g.
In values\string.xml:
<resources>
<string name="app_name">Resource Tester</string>
<string name="action_settings">Settings</string>
<string name="myindicator_lang">en</string>
<string name="myindicator_dpi">normal</string>
<string name="myindicator_orient">port</string>
</resources>
In values-de\string.xml:
<resources> <string name="myindicator_lang">de</string> </resources>
In values-land\string.xml:
<resources> <string name="myindicator_orient">land</string> </resources>
In values-hdpi\string.xml:
<resources> <string name="myindicator_dpi">hdpi</string> </resources>
etc.
With this string info returned at runtime, I can just dynamically build the required file name based on device configuration, allowing me to store alternative server/local storage resources with an appropriate name and have my app utilise the most appropriate image file if it exists.
i.e. in server/local storage have:
mybanner-en.jpg
mybanner-de.jpg
mybanner-de-land.jpg
etc.
I can now search for an existing stored file which best matches the device config at the time.
Many thanks Rajesh, for pointing me in the right direction.

Internationalization of string.xml issue

In my application I do have several different string resources each per locale like:
res/values/string.xml //default
res/values-en/string.xml //english
res/values-it/string.xml //italian
Now the problem - each of files contains hundreds of keys and from time to time I can't really define which language is lacking some keys. Say:
<string name="yes">Yes</string> <!-- Default -->
<string name="yes">Yes</string> <!-- English -->
<string name="yes">Si</string> <!-- Italian -->
And if in German string.xml there'll be no "yes" key corresponding value will be default "Yes" instead of German "Ja" - which is disaster.
Help me to find a way to define lacking string resource keys.
You can also try MOTODEV Studio. You can use it a standalone IDE (based on Eclipse) or as an Eclipse Plugin. What you would like is an editor, which includes, that makes really easy working with localizable strings. It will show you in a same view all the files as columns, so you will not need to do any merge or diff whatsoever.
Use http://winmerge.org/
You can compare files easily.
copy all the files to one text file,, Sort the file and then check one key at once,, loooong method but the most effective one

Categories

Resources