Suppose I have an android app, say com.acme.game
This app is using different assets to achieve localization.
What will be the best strategy for building this App (apk) ?
Should I create separate projects for each "locale" and name it com.acme.game.en, com.acme.game.rus... accordingly,
or there is a better way without any duplication?
You can keep a single package name and just add different assets for various locales in appropriate folders. Read more about it here
Related
In the app I'm building, I'm using multiple languages. It's easy to add a different language into an app by adding a new folder (for example: values-fr) and adding a new strings.xml file in there. But I have pretty large text files (complete articles) that I need to add. These articles are also written in different languages. What is the best way to add them to my app?
I'd consider using res/raw-<qualifiers> as alternative to the assets. The raw folder can store arbitrary files in their - you guessed it - raw form. For example, a 'Hello World' article written in French and English, would be stored under:
res/raw-fr
res/raw-en
The raw resource can then be opened by calling openRawResource(int id) on a resources object, similar to how it works for other resources like drawables, strings etc. The id's generated by the framework will be in the familiar format of R.raw.filename (without file extension).
The benefit of using this approach is that you can fully leverage Android's localization system, meaning that as a developer you basically don't have to worry about any of that at all. You can also easily add more qualifiers to further filter on device characteristics (e.g. screen size, density, platform version etc etc - see here for a full overview). The downside is that it imposes some limitations in terms of the original file name/extension and doesn't support a proper folder/file hierarchy.
The 'better' approach (/raw vs /assets that is) will probably depend on your project's requirements.
I would probably use assets -- that is, create assets/data/fr/ and store the fr files there. Note that assets require explicit extraction -- which probably is good since you may save memory having only one set of articles installed.
Another possibility is to place everything on an http server, and thus make both keeping and accessing the articles somebody else's problem :) .
BTW, if you files are really big, you will have to install the application without them, and download the articles later. (There are restrictions on the apk size.)
If I want to upload my Android app with an aim of supporting multiple languages, do I have to upload multiple .apks, each designed for the language I would like to support, or do I implement it all into one .apk file?
Note: My app is a game and does not really not contain any Strings in the UI. The UI was made using Photoshop, eg the buttons with text and so on.
If I pack all the languages into one .apk file, how do I check which language the app should use?
Update:
All my images are stored in the assets folder of my project. How would I localize them?
No, you don't need to create multiple APKs, just single APK with Localization, see this http://developer.android.com/training/basics/supporting-devices/languages.html
and this http://developer.android.com/guide/topics/resources/localization.html
before given your question answer,i tell you about multilingual in android basically in android application work in region wise means if i have device in usa -> install one application ->once it install if application was developed for multilingual support then it automatically render those string.
-> now question is how application build in multilingual for that you have to define string.xml for each language for your application will supports.
--for example : res/values <= default
--for Spanish : res/values-es
--for your question answer : if you define image with static way then it does not work.
For games that have images containing text you can use the same method as for normal strings.
Lets say, for strings you will have a strings.xml file under
values-en
values-es
values-de
values-fr
Then for images you can use (beware of the qualifiers precedence)
drawable-es-hdpi
drawable-en-hdpi
drawable-de-hdpi
drawable-fr-hdpi
However this will make your app bigger.
What I usually do is to generate the images programmatically, using a background and then rendering the text using some custom font on top of it. Even if the images are textures to be used on a 3D engine it works fine and I believe is a more reasonable approach.
I am a newbie for android and really need you all helps to complete my task ^^. I am currently doing a project which is quite similar to android localization. However, there is another native language that is not stated down in language or a language-region combination that provided by the android setting. Is there any other ways that i can do to make the application retrieve different strings when different language selected?
I have try to create different names of values folder but it doesn't work when the folder named as "values-penan".
Thanks if anyone could help!
I have a non-standard Android application that has a requirement to load resources from an external file that is not part of the application apk. These resources will be packaged separately and delivered as its own package.
There are a few different types of items that will be part of this external resource bundle. One of those items includes the localized strings.xml file. This philosophy allows the change of a string / translation that does not affect the deployment of the application (in other words, application.apk stays in tact, but the only difference is a new strings.xml).
I've been searching around, and this doesn't seem possible. Is there any way? Or does this philosophy mean completely abandoning the resources all together and writing a custom layer to pull these strings and other external resources from a file?
The application is for Honeycomb platform.
Thanks in advance for any advise.
The best way to do this, I think, is to package your resources as a ContentProvider. See the guide topic Content Providers for how to get started doing this.
I have an app on the iPhone and need to port it to android. For this I would like to group screen related files like classes and xml per screen in one "screen group" per screen somehow, ideally also strings and other value files
if I use folders I can only group res files separately and src files separately.
what would be the best way?
Thanks very much!
EDIT:
If that should not be possible, how to best then solve this issue? Do you create a subfolder in the src and another in the res for each screen?
The way you group files for the iphone is not possible for an android project. Android has pre determined folders which hold specific files, if you break this structure, your building process will fail. Its not ideal but that just how it it.
When it comes to source java files, they follow the concept of packages which are basically folders. The 'src' folder is the part where you can create sub folders as you desire. If you are adamant about keeping the files related to a screen in one place, you should create the layouts with java code and not use layout xml files.
But using xml layout files make development much easier and faster. Consider that as the presentation and java files as the logic+data. So group java files as you want and leave xml files in the layout folder with easy to identify names.
android uses certain directory layout for project structures (i.e. convention over configuration). Basically you will want to put your XML layout files in res/layout directory. Please read http://developer.android.com/guide/developing/projects/index.html#ApplicationProjects for further information.
Unfortunately, there's no easy way to do this in Eclipse. You can't create custom directories in your Android app's /res directory, you can only use permitted dir-names. E.g. you can't have a /res/layout-myscreen1 and /res/layout-myscreen2. You also must put your resources in /res, and your code files in packages, so they're at separate places in your project.
You can use Working Sets to group related files together however, but they're quite painful to use IMHO. Check the eclipse docs and tutorials out on them.