Which is the best way to have a multilanguage app? Should I create a set of strings written in my language and then use an google api that translates online on-the-fly? Any code example? And, how to get the language of the user and how to pass this information to the api?
I wouldn't trust on-the-fly translation of your strings; even the best automatic translators can produce inaccurate output. Additionally, you add a fair amount of complexity, overhead, and dependency (e.g., having a network connection) by handling translation this way.
The problem of having a "multilangauge app" (as you called it) is well-known, and the process of solving it is called internationalization and localization. In general, when you're working with a framework or programming language, you can look for existing packages/libraries relating to this topic -- it's almost a given that others have spent significant time building a good mechanism(s) to facilitate this.
Android is no exception; it's been developed with localization support built-in. The Android Developer Documentation has a comprehensive guide on Localization that you should take a look at. You'll still need to translate your text somehow, but a lot of the "groundwork" of how you can serve up locale-specific messages to the user has already been laid out for you.
One last note -- the Android docs also provide a tutorial called "Hello, L10n", which walks you through the basics of creating a localized app. Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With