This one puzzles me since my first android project. Consider multi-language string resources with 'en' as the default:
res/values/strings.xml <--- The default language 'en'
res/values-de/strings.xml <--- de
res/values-fr/strings.xml <--- fr
res/values-it/strings.xml <--- it
With that folder structure the Android Market entry for this app shows language support for "default, german, french and italian only". Yes, english is missing in that list.
Is it possible to "include" the complete default strings resource from the "values" folder in an additional "values-en" folder. And yes, I don't want to maintain that file in that new folder because everything is declared in the default string resource already.
Many thanks in advance.
Harald
I don't quite understand where the problem is. Just create a values-en directory and copy'n paste the XMLs from your default directory to the new one.
If you just want to have a kind of symbolic link to that default values directory so that when you change something inside the default directory the files i the linked directory represent the same changes then you just go to File -> New -> Folder select where the new folder should be created (in your case the res directory) and then hit on Advanced >> and there select Link to alternate location (Linked Folder) then browse to the directory you want to link to (in your case the values directory) and your done.
Now whenever you change something inside the values directory all your changes apply to the new linked directory.
Related
I am currently translating my android app via the embedded translations editor of android studio. Within the locale menu, I could either choose a general language or a language/dialect connected to a specific country. For instance German (de) or German (de) in Austria (at) or German (de) in Belgium (Be) etc..
In case I would like to reach users in all Spanish speaking countries, is it enough to add just a general Spanish locale in my values-es folder or should I create a Spanish locale for each hispanophone country? The second option would not make sense to me, especially since the app is not that complex, that it has to support dialects or varieties.
In the Project, at the left side, select option Project Files, so one can see the directory structure of the current project.
Under the res directory, there is a folder values... for each desired language and country combination, and within each one there is a strings.xml file created. That files should contain all the words translated in the related language.
The simplest way is to initially create a general file with the Spanish language (es): it would be the values-es folder (created by right clicking mouse on the res directory, option, then new, Android Resource Directory and selecting the Spanish language.
After one should create a new empty strings.xml file, created under this new folder (value-es) Right mouse click in the new folder, select option new, Values Resource File, named it strings.xml.
This file will contain all the words in your app, under the common general structure, that should be in each strings.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<-!--strings-->
</resources>
However, there are some cases that will be exceptions and you will need to create more specific files. Let's assume the one needs the app for Chile. So it to be created a new folder. Also use new, Android Resource Director, and choose Spanish and Chile. The new folder will be called values-es-rCL. Under this folder, one needs to create other empty Strings.xml with the above initial content.
This file will be almost empty
Howeever there are exceptions: savories is tapa in Spain, but in Chile is picoteos.
If default language is English put:
Under values folder in strings.xml:
savories
Under values-es folder in strings.xml:
tapas
Under values-es-rCL folder in strings.xml:
picoteos
So where appear savories, the app searchs in specific country (values-es-rCL), if it didn't find, it search in language (values-es),if it also didn't find, it search in default language (values)
For a normal word, like tap, it just necessary put the word grifo in spanish language, with no worry about chilean strings.xml
if someone needs to be compatible with Mexico, then it will be necessary to create strings.xml and the folder values-mx-rMX for this "dialect". local translatio for 'savories' is the word botanas
I am using Assets files as help files in my app and have well over a dozen. I am porting the app to multiple languages. Where do the alternative language asset files go?
I am already using the "res/values" directories for language files (values, values-es, etc) for use within the app. I thought the "Assets" directory was for help files and items like that.
I am trying to NOT muddy my values folders with the many help files that I am including and was using "activity.getAssets().open( file )" to read the files.
Also, some of these "Asset" files are different language pictures.
Can you put the files in /res instead of /assets? This has built in support for multiple languages, there is an easy to follow guide here.
Basically, if your original text is in /res/values/strings.xml, for example, you would put your translations in /res/values-{ISO LANGUAGE CODE}/strings.xml
For example, your French translation would be in /res/values-fr/strings.xml.
Android will pick the appropriate translation file according to the locale of the user's phone.
There are some good explanations of the other differences between /res and /assets here.
For the voice recognition in my app (using Vosk) I have defined the specific asset folder as resource string.
I.e. values\strings.xml contains:
<resources>
<string name="language_directory">vosk-model-small-en-us-0.15</string>
...
and values-de-rDE\strings.xml contains:
<resources>
<string name="language_directory">vosk-model-small-de-0.15</string>
...
So I can access the asset directory via
val assets = Assets(activity)
val assetDir = assets.syncAssets()
val modelDir = activity.getString(R.string.language_directory)
recognitionListener.model = Model("$assetDir/$modelDir")
This way the correct directory is always chosen based in the active locale.
In my case, those are located at models\src\main\assets\sync\<language_directory>
Make folder in assets:
1. htmlpagesNL
2. htmlpagesUS
Copy file from htmlpagesNL and paste to htmlpagesUS and Translate
Use url inside Nl string file:
file:///android_asset/htmlpagesNL for NL translation
Use url inside Us string file:
file:///android_asset/htmlpagesUS for US translation
Support different languages
Support different languages and cultures
Each time I create values_enu folder under res folder in eclipse for localization issue I get an error invalid resource directory name
http://developer.android.com/training/basics/supporting-devices/languages.html
Can someone help please.
One thing that wasn't clear to me from the docs is what a directory should be called in case of language variants, e.g. British/American English or German/Austrian German.
So even though the locales are of form en_GB, en_US, de_DE or de_AT etc, the corresponding folders should be called
res/values-en-rGB/
res/values-en-rUS/
res/values-de-rDE/
res/values-de-rAT/
That means keep the letter capitalization but use only hyphens instead of underscores and add an r before the language variant.
Use hyphen(-) instead of underscores(_)..
values-en is valid and values_en is invalid
You only should write "values-en".
The syntax is: FOLDERNAME MINUS 2-CHARACTER-LANGUAGE-KEY
Another example:
drawable-es <<= this will create a folder for Spanish picture files. It could be useful for implementing a labeled button you have created in photoshop or gimp.
I have the next problem:
When I add a new folder called "values-en" and I move the strings.xml file from the default folder "values" to that "values-en", I always get the next error:
Couldn't resolve resource #string/my_string
I have cleaned the project and refresh and the warning is always there.
Is there any restriction where I must always have a strings.xml in the device folder "values"?
Someone has experimented the same?
Thanks in advance
You must have the values folder. To support multiple languages you can add the other values folders (values-en, values-fr, etc).
In the default values folder you declare your strings in your app's default language and in values-en the same strings but with their english translation.
Good morning. Into my android application I have in assets directory a file changelog. I have creato also the directory assets-it and I have put into the file changelog in italian language but when I start the application it always display the file into assets directory also if the device language is set to italian. Why ?
That is the expected behavior. Resources in res/ can be localized in that manner, but the assets/ directory cannot.
Since it's just a changelog, I'd recommend storing it as a localized string resource in res/values-LOCALE/. If you really want localization of assets, you could manually recreate it by getting the current locale and loading, e.g. assets/changelog-en, vs. assets/changelog-it, but I think that would generally not be a good idea, and it certainly isn't necessary in your case.
Try this:
put both changelog files into assets folder:
Path is for example: assets/en/changelog_file and assets/it/changelog_file
enter this into your values/strings.xml:
<string name="changelog_file">file:///android_asset/en/changelog_file</string>
put in your values-it/strings.xml:
<string name="changelog_file">file:///android_asset/it/changelog_file</string>
Like this you can call the string from the code:
getResources().getString(R.string.changelog_file) and it will call the values-en or values-it according to device locale.