24

I want to change language via ADB. I try:

adb shell setprop persist.sys.language fr;setprop persist.sys.country CA;stop;sleep 5;start

but I get errors:

setprop: command not found
stop: missing job name
Try `stop --help' for more information.
start: missing job name
Try `start --help' for more information.

what is wrong? I want to do this on physical device

beigirad
  • 4,986
  • 2
  • 29
  • 52
user3258796
  • 265
  • 1
  • 2
  • 8
  • 1
    I didn't even know it's possible to do it via adb... – android developer Feb 11 '14 at 20:23
  • Try getting an interactive shell first and issuing your commands one by one. That may eliminate any issue with your host system interpreting or altering the series of commands (the stop and start error messages look suspiciously like the are trying to run on the development system rather than the android device). You could also try quoting everything after `adb shell` – Chris Stratton Feb 11 '14 at 20:28
  • possibly your device does not have setprop accessible to the adb user. – njzk2 Feb 11 '14 at 21:15
  • @njzk2, that is not the case. – Alex P. Feb 11 '14 at 21:23

15 Answers15

32

Your errors have nothing to do with adb. You must first understand how your local shell processes your command: What you are doing is running these commands locally (on your PC):

adb shell setprop persist.sys.language fr
setprop persist.sys.country CA
stop
sleep 5
start

and the error messages you see are from local shell (i.e. there is no setprop executable on your system and start and stop commands have non-optional parameters.

the correct command would be

adb shell "setprop persist.sys.language fr; setprop persist.sys.country CA; setprop ctl.restart zygote"

The argument between the quotes will be passed to adb instead of being interpreted by your local shell.

In more recent Android versions, you can also do:

adb shell "setprop persist.sys.locale fr-CA; setprop ctl.restart zygote"
Vadim Caen
  • 1,526
  • 11
  • 21
Alex P.
  • 30,437
  • 17
  • 118
  • 169
14

You can change the locale/language for testing purposes without rooting the device, also on newer (4.2+) devices. You have to create an application that changes the device locale. Or, you can use a helper app, e.g. ADB Change Language.

Next, on 4.2+ devices, you have to use grant the app CHANGE_CONFIGURATION permission via adb, adb shell pm grant <package_name> android.permission.CHANGE_CONFIGURATION.

Finally, you can use adb commands (launch activity) to switch locale.

Community
  • 1
  • 1
Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98
  • 1
    `Operation not allowed: java.lang.SecurityException: grantRuntimePermission: Neither user 10174 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS` – Alaa M. Jun 25 '19 at 20:00
  • @AlaaM. I was able to fix that by enabling "USB debugging (Security Settings)": https://stackoverflow.com/a/53938414/5090928 – serg06 Jun 01 '21 at 23:24
11

There is few solutions.It works for me.


1.

adb shell am start -a android.settings.LOCALE_SETTINGS (You could see the language menu, then choose language by appium)


2.

download adbchangelanguage on google store

adb shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE_CONFIGURATION
adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language zh -e country TW

https://gist.github.com/douglasselph/b9998e69998759c6cceec1df1aa96ac5


3.

using appium then set desired capabilities (language and locale) http://appium.io/docs/en/writing-running-appium/caps/

Carsten Hagemann
  • 957
  • 10
  • 23
KNewman Liuu
  • 136
  • 1
  • 5
  • Does not work for new API 31+ devices. – Ragen Dazs Aug 13 '23 at 22:15
  • I have a Chinese phone (Vivo X90 Pro+) running OriginOS 3 / Android 13 and this was enough to bring up the hidden language menu: `adb shell am start -a android.settings.LOCALE_SETTINGS` – miff2000 Aug 22 '23 at 22:40
6

Run through the following steps:

  • Create emulator with google APIs Intel x86
  • Root the emulator, by running the command:

    adb root
    
  • Run the following shell command through adb:

    adb -e shell "su root; setprop persist.sys.locale pt-PT; stop; sleep 2; start” 
    

    then, exit the shell which restarts the emulator.

  • Locales we need for screenshots:

    de_DE
    en_EN
    fr_FR
    ko_KO
    pt_PT
    es_ES
    ja_JA
    
Tim Visée
  • 2,988
  • 4
  • 45
  • 55
niti
  • 129
  • 1
  • 6
4

This is all over the place, to put it simply

setprop will only work on an AVD or a rooted physical device

The alternative is to use the settings in the Launcher.

Rooted device or AVD this works:

<android-sdk path>/platform-tools/adb shell
root@generic:/ # getprop persist.sys.language
getprop persist.sys.language
en
root@generic:/ # setprop persist.sys.language fr
setprop persist.sys.language fr
root@generic:/ # setprop persist.sys.country CA
setprop persist.sys.country CA
root@generic:/ # stop
stop
root@generic:/ # start
start
root@generic:/ # sleep 5
sleep 5
root@generic:/ # getprop |grep lang
getprop |grep lang
[persist.sys.language]: [fr]
root@generic:/ # getprop |grep country
getprop |grep country
[persist.sys.country]: [CA]
root@generic:/ #
Tricia
  • 43
  • 3
2

Try this

adb shell "su -c 'setprop persist.sys.language fr; setprop persist.sys.country CA; stop; sleep 5; start'

You need a rooted device.

Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
  • Wrong syntax, maybe. I'm doing some research right now with Google to know more about it. Or maybe missing commands is caused by no-rooted device which hides this commands? No idea, i got this command time ago somewhere which worked when i used it. – Marco Acierno Feb 11 '14 at 20:29
  • I need to do this on no-rooted device. – user3258796 Feb 11 '14 at 20:31
  • or maybe You have any idea for change language using appium and python? I need this for Automated tests – user3258796 Feb 11 '14 at 20:40
2

To set the language to US English, run the following command in the terminal:

adb shell "setprop persist.sys.locale en-US; setprop ctl.restart zygote"

To change to other languages, refer this list of languages: https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/localization#locale-codes

Sulav Timsina
  • 703
  • 7
  • 20
1

On Emulator: When changed language manually, it stopped working and had to do wipe data of Emulator in AVD manager to make it work again.

And the script used:

adb shell "su 0 setprop persist.sys.locale ja";adb shell "su 0 setprop ctl.restart zygote"

May add ;sleep 20 in the end if some commands in script below this command depend on device to be ready.

vbevans94
  • 1,500
  • 1
  • 16
  • 15
1

According to official documents:

To change the locale in the emulator by using the adb shell.

  1. Pick the locale you want to test and determine its BCP-47 language tag, for example, Canadian French would be fr-CA.

  2. Launch an emulator.

  3. From a command-line shell on the host computer, run the following command:

    adb shell
    

    or if you have a device attached, specify that you want the emulator by adding the -e option:

    adb -e shell
    
  4. At the adb shell prompt (#), run this command:

    setprop persist.sys.locale [BCP-47 language tag];stop;sleep 5;start
    

Replace bracketed sections with the appropriate codes from Step 1.

For instance, to test in Canadian French:

  setprop persist.sys.locale fr-CA;stop;sleep 5;start 

This causes the emulator to restart. (It looks like a full reboot, but it isn't.) Once the Home screen appears again, re-launch your app, and the app launches with the new locale.

beigirad
  • 4,986
  • 2
  • 29
  • 52
1

In case this helps someone: I changed my phone's language to something buggy called en-XA (it was called English one in the UI I believe?) by mistake, and I couldn't even unlock the screen, but I had to fix my language settings somehow. I had no root access, but I had a custom recovery (TWRP) flashed fortunately.

The solution for me was to edit the /data/system/users/0/settings_system.xml file, this line in particular:

<setting id="24885" name="system_locales" value="en-XA,pl-PL" package="android" defaultValue="en-XA,pl-PL" defaultSysSet="true" preserve_in_restore="true" />

I changed the en-XA to en-US, rebooted, and the phone works again!

You can edit the file using your recovery's built-in file editor or use /adb pull /data/system/users/0/settings_system.xml to download and edit the file locally, then adb push settings_system.xml /data/system/users/0/settings_system.xml to update it on the device.

BTW I also changed the en-XA to en-US in the /data/property/persistent_properties file before and it didn't work alone, but perhaps both are needed.

Everything tested on a clean Android 11 device.

Nicofisi
  • 1,083
  • 1
  • 15
  • 27
0

For Android M or newer, you need use:

setprop ro.product.locale xx-XX
setprop persist.sys.locale xx-XX

xx is language, XX is country

0

The solution to do it without rooting. You can use something like this the below function. The function goes into settings and exercises the UI to change the locale settings.

https://github.com/dtmilano/AndroidViewClient/blob/480ab93dbd01296a68c1ce7109ceb8275d1ed8a7/src/com/dtmilano/android/viewclient.py#L1302

The tricky part is to get to the right language when you are in a different language. You would think the language always maintain the same index in the list, but unfortunately not. So you have to have a solution like this.

Con: You my have to tweak it a little for handling different phones, the settings may have a different order.

anotherCoder
  • 712
  • 3
  • 11
  • 25
0

The solution for API 28+ is

adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "en_US" com.android.customlocale2
  • 2
    Adding some commentary will go a long way to explain why this solves the OP's question. Just a code dump alone is not that helpful. – SiKing Sep 22 '20 at 20:50
  • Also, whenever possible, it's recommended to post long lines of code across several lines, so visitors can read your suggested answer without requiring them to scroll horizontally. Especially for mobile users. Often, users will skip over such answers, preferring to read of that does not require scrolling just to view. Of course, sometimes it is not possible. One hack in that case is that sometimes you can instead use inline code formatting, which will wrap the indicated code across several lines. This hack would not be useful for long code blocks, but sometimes for a single long line, it works – SherylHohman Sep 22 '20 at 21:59
  • One way to improve your answer would be adding a link to documentation. Another would be to explain why/how key parts of your solution address the issue, or differs from other solutions. Or point out any edge cases for its usage. – SherylHohman Sep 22 '20 at 22:05
0

Instead of setprop, this can be used without root:

Read all languages:

adb shell content query --uri content://settings/system --where "name=\'system_locales\'"

Delete all languages:

adb shell content delete --uri content://settings/system --where "name=\'system_locales\'"

Add new language en-US:

adb shell content insert --uri content://settings/system --bind name:s:system_locales --bind value:s:en-US
Lexycon
  • 23
  • 5
-6

You cant do that with the adb on your device. Your adb outside the device, I mean on your computer connected with usb, can change it with passing a permission before changing the language.

On your device directly, you need a rooted device.

Luser_k
  • 514
  • 1
  • 4
  • 18
  • so, what You propose? I can't root device. I need change language via appium and python – user3258796 Feb 11 '14 at 21:07
  • So why do you give me a "-1", when it is on device without rooting not possible ? There is another option you can do... you need a server-client, that means your app and server communicates and the device sends a command to do a screenshot by the adb on the server! In other words, not the adb on your device is doing the screenshot, the adb on the server is doing it. Its a good workaround. – Luser_k Feb 12 '14 at 16:54
  • I don't give You any points. I have to small point of reputation to vote – user3258796 Feb 12 '14 at 21:55