3

Is it possible to restrict the language in an android application, i.e When user change language i want only English and French languages needs to get effected.Problem is when user select the Dutch the Options Menu names are in in English but MORE(System generated menu option if there are more options to display) is in Dutch.I want More to be in English.
Please Help
NITZ

NitZRobotKoder
  • 1,046
  • 8
  • 44
  • 74
  • So what you want to do is modify the user's language settings so a system level menu works differently? Why? – Security Hound Jun 22 '12 at 11:53
  • My Application will support only two Languages!!!!I want MORE to be in English or French – NitZRobotKoder Jun 22 '12 at 12:00
  • 2
    So you say that Dutch speaking people will always understand the English? Why not contact some people that can translate the strings in your application to make it multilingual? – TimVK Jun 26 '12 at 12:23
  • I think you can do something like a trick that, if user have selected Dutch lang, and then when it comes to your activity where there is menu MORE ..so programmatically change locale to ENGLISH and as soon as the menu is hide or in Activity onDestroy change LOCALE again to Dutch. – MKJParekh Jun 27 '12 at 05:14

3 Answers3

8

You can set the locale programmatically in your app:

  Configuration configuration = context.getResources().getConfiguration();
  configuration.locale = new Locale(selectedLanguage);
  context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());

where selectedLanguage is a variable that holds your language abbreviation, and context holds a reference to the Context.

These earlier answers on SO discuss possible solutions further:

Change language settings (locale) for the device

Changing Locale within the app itself

Change language programmatically in Android

Community
  • 1
  • 1
Gunnar Karlsson
  • 28,350
  • 10
  • 68
  • 71
1

The word "More" that shows up in the options when you press the menu key is a system generated string so it will match whatever the system language is regardless of what your app supports.

If you want the word "More" to show up in either French or English, you'll have to cut down the number of menu items you have so that the system doesn't show it, then manually add a "More" option. The more option you add manually won't automatically show the rest of the menu options so you'd have to move them to their own context menu.

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
0

I think you can resolve your issue in two ways.

First one, change your "More" resource string to a resource file like the following one:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"tools:ignore="MissingTranslation">
    <string name="more_btn">More</string>
</resources>

Or, you can simply duplicate the string value into values-fr and values-en directories.

yugidroid
  • 6,640
  • 2
  • 30
  • 45
  • @NitZRobotKoder, I thought you was implementing your own context menu. Natively, I think you can't do it, but I'm not 100% sure about that. – yugidroid Jul 02 '12 at 23:36