I have an app originally written in UK English, hence all of the strings in res/values/strings.xml are in UK English.
I would like to provide a "translation" to US English. For the most part US and UK English are exactly the same, so in the US translation file I only want to specify those few string changes which are affected (about 10 of 120).
I have tried creating a res/values-en-rUS/strings.xml file (this name given by Android Studio) in which I've added only those 10 strings which differ. But Android Studio gives me errors in my main strings.xml for all the remaining strings: "XXX" is not translated in "en" (English).
So, how can I efficiently provide translations to US English - ie specify only the 10 lines, without having to duplicate all the others? Duplication is always bad for code maintenance!
You can use translatable="false" settings to flag string resources that should not be translated. Something like:
<resources>
<string name="app_name" translatable="false">EasyApp</string>
<string name="action_settings">Settings</string>
<string name="easy_app">I am a Simple App!</string>
<string name="next_page">Next Page</string>
<string name="second_page_message">I am the Second Page!</string>
<string name="title_activity_second">SecondActivity</string>
</resources>
In the above sample, the app_name will not have to be translated in other locales. This way in the default strings.xml you can provide the UK version and mark with translatable="false" all the resources that you would like to maintain in US version to be the same. In res/values-en-rUS/strings.xml you will have to add only the messages that you need to maintain in US English.
Please note that if you are planning to use other locales/languages this method may not be the appropriate one, since this way you specify that the translatable="false" resources are the same for all locales.
You can check the Configure untranslatable section rows if you need more details.
Related
I would like to provide my own translations for my new Android app without using the Translation Service in Google Play Console. I have already provided translations for the app descriptions but this would be for the buttons and strings in the app.
I started to upload the xml files into the Translation Service, but then decided I don't want to pay for something that I can already translate myself. What is the best way to do this?
For example, English:
<resources>
<string name="SaveSetting">Save setting</string>
<string name="ViewSettings">View settings</string>
<string name="SavedSettings">Saved settings</string>
<string name="settingHint">Enter the setting name</string>
</resources>
Portuguese:
<resources>
<string name="SaveSetting">Salvar configuração</string>
<string name="ViewSettings">Ver configurações</string>
<string name="SavedSettings">Configurações salvadas</string>
<string name="settingHint">Nome da configuração</string>
</resources>
You create multiple string files, one for each language and the phone will automatically use the one based on the OS settings
see here: https://developer.android.com/guide/topics/resources/localization
In your case you would put your default strings in the res/values/strings.xml and the Portuguese ones in a res/values-pt/strings.xml
If you are using Android Studio, you can Open the translations editor and then add the translations for your app's strings on any language.
For more details check: https://developer.android.com/studio/write/translations-editor
Try using this tree in your project with correct folders and strings.xml suffix:
MyProject/
res/
values/
strings.xml
values-b+es/
strings.xml
mipmap/
country_flag.png
mipmap-b+es+ES/
country_flag.p
"es" for Spain, "us" USA...
Take a look:
https://developer.android.com/training/basics/supporting-devices/languages
I've been working on an Android application that is going to be used throughout different countries.
Because of this I have followed the Android Developer Guide to support different languages for an application and used the Translation Editor in Android Studio to specify the resources I want translated. However the preview Android Studio gives me shows the correct resources, they aren't translated and instead kept at the default value when I run the application. I believe I might have missed something and can't seem to find what it is.
The following images show the directories and resource Strings in Android Studio:
Default strings:
<resources>
<string name="welcome_user">Welcome %1$s</string>
<string name="logout">Logout</string>
<string name="main_menu">Main menu</string>
<string name="inventory">Inventory</string>
<string name="login">Login</string>
</resources>
Spanish strings:
<resources>
<string name="welcome_user">Bienvenido %1$s</string>
<string name="logout">Cerrar sesión</string>
<string name="main_menu">Menú principal</string>
<string name="inventory">Inventario</string>
<string name="login">"Iniciar sesión "</string>
</resources>
I refer to the resources in my layout xml like one would normally do like
android:id="#+id/textWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_user"
The following images are what Android Studio shows me when I set it to the Spanish locale (different String resources than the ones above) and what is shown when the application is ran even though the device language is set to Español:
Alright, I found an answer on this post after searching related documentation and questions. The problem wasn't coming from the structuring of my folders or how I retrieved the resources.
The resConfigs property in my Android Gradle file was set to only support language resources related to English resources. Because of this setting any other language that was not specified got removed.
After I added "es" and "nl" everything showed up as intended.
productFlavors {
dev {
dimension "default"
applicationIdSuffix '.dev'
versionNameSuffix '-dev'
resConfigs "en", "nl", "es" //The culprit I created and forgot
}
I am using takephoto_library for selecting multiple images.
https://github.com/crazycodeboy/TakePhoto
It is working properly but as you can see in the below screenshot, the caption is in Chinese.
I found that the view control is "com.darsh.multipleimageselect.activities" and Id of this caption is in the below
actionBar.setTitle(R.string.album_view);
Is there any way to change this string to English?
Is there any way to change this string to English?
Yes, you can change all the Strings in strings.xml
https://github.com/crazycodeboy/TakePhoto/blob/master/takephoto_library/src/main/res/values/strings.xml
Change these two chinese word to english
<string name="add">确定</string>
<string name="selected">已选</string>
In English
<string name="add">confirm</string>
<string name="selected">selected</string>
Try this .
find the strings.xml(values) and strings.xml(values-en) in the library of TakePhoto .
And change the string name to the English .
In the strings.xml(values)
string name="add">确定</string>
<string name="selected">已选</string>
<string name="limit_exceeded">最多能选 %d 张</string>
And add this to the strings.xml(values-en)
string name="add">confirm</string>
<string name="selected">selected</string>
<string name="limit_exceeded">You can choose%d at most</string>
And you can change this strings.xml(values-en) and strings.xml(values)
For internationalization, android looks in different directories for the appropriate local as determined by your selection for the phone. For instance, you should see something like this:
./explorer/src/main/res/values-uk/strings.xml
./explorer/src/main/res/values-tr/strings.xml
./explorer/src/main/res/values-ru/strings.xml
./explorer/src/main/res/values-pl/strings.xml
./explorer/src/main/res/values-de/strings.xml
./explorer/src/main/res/values-ko/strings.xml
./explorer/src/main/res/values-sv/strings.xml
...
Where the translated strings are in the values-../strings as determined by the res/values/strings.xml.
In my case, res/values/strings.xml has an entry:
<string name="createnewfolder">Create new folder</string>
which is translated in values-uk/strings.xml as
<string name="createnewfolder">Нова папка</string>
You might find Localizing with Resources useful.
I have two string xml for two different languages, I would like to know the different between those xml files.
For example, there is one xml for English,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Keep Accounts</string>
<string name="insertNewOne">Insert Accounts</string>
<string name="browseRecord">Browse Records</string>
<string name="set">Setting</string>
</resources>
And another xml for other language,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Example</string>
<string name="insertNewOne">Example</string>
<string name="browseRecord">Example</string>
<string name="dateNoColon">Example</string>
</resources>
We can see the difference is xml for English has element string name="set", and the other has not. On the other hand, the xml file for other language has element string name="dateNoColon" but the xml for English has not.
In this case, I would like to know the English xml lacks the element string name="dateNoColon", and other xml lacks the element string name="set".
Android Studio has translations editor starting of 0.8.12 version. You can find there missing translation strings.
You can enable check for missing translations in Lint tool. There are "Missing translation" and "Extra translation" checks.
Extra translation If a string appears in a specific language translation file, but there is no corresponding string in the default locale, then this string is probably unused. (It's technically possible that your application is only intended to run in a specific locale, but it's still a good idea to provide a fallback.).
Incomplete translation If an application has more than one locale, then all the strings declared in one language should also be translated in all other languages.
Suppose if the device is set to Other language, Android will look for title in the otherlanguage.xml file in value folder. But if no such string is included in that file, Android will fall back to the default, and will load title in English from the english.xml file.
For more detail go to http://developer.android.com/guide/topics/resources/localization.html#using-framework
I wrote a small tool for that: resdiff.
Check it out! https://github.com/danijoo/resdiff
Try sorting both files using some perl or bash script or something like that for example, using bash:
sort temp.txt -o temp.txt
and then look at the diff for example using DiffMergeit.
Use Android Lint to find both incomplete translations i.e. strings missing in a language variant and extra translations i.e. strings introduced in a language variant but missing in the default locale.
In Android Studio you can run Lint (and some other analysis tools) with Analyze -> Inspect Code.
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