locale

Locale: Language name to Country / Language code

陌路散爱 提交于 2019-12-12 14:24:00
问题 EDIT: I have a language name in English, nothing else. How do I get the code for it. e.g.: English -> en German -> de Spanish -> es Chinese -> zh 回答1: We have to set the Language name and country name for locale to get this // Locale(String language, String country) Locale locale = new Locale("German" , "DE"); // print ISO3 country name for corresponding locale System.out.println("Name:" + locale.getISO3Country()); This returns ISO3Country name as DEU 回答2: LanguageCode enum contained in com

Change language on Firefox with Selenium Python

谁说我不能喝 提交于 2019-12-12 14:02:01
问题 I am trying to change the language of Selenium Webdriver Firefox from English to Spanish. I have the following code in place: def get_webdriver(attempts=3, timeout=60): firefox_profile = webdriver.FirefoxProfile() firefox_profile.set_preference("intl.accept_languages", "es-es") desired_capabilities = getattr( DesiredCapabilities, "FIREFOX").copy() hub_url = urljoin('http://hub:4444', '/wd/hub') driver = webdriver.Remote( command_executor=hub_url, desired_capabilities=desired_capabilities,

lon,lat to timezone

牧云@^-^@ 提交于 2019-12-12 13:41:04
问题 Does anyone know if there is any existing solution for determining a timezone from a point (lon, lat)? i could hard code the few i need for this project but it'd be better to use a pre-built solution. thanks. 回答1: Use a webservice such as the one provided by geonames. Example: http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo Returns: ... <timezoneId>Europe/Vienna</timezoneId> ... 回答2: Try this code for use Google Time Zone API: String get_xml_server_reponse(String server_url)

How to set a custom thousands separator?

一个人想着一个人 提交于 2019-12-12 12:32:00
问题 I know that theoretically digits in large integers can be grouped by thousands for better readability: Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import locale >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') 'en_US.UTF-8' >>> locale.format('%d', 1234567890, grouping=True) '1,234,567,890' >>> "{:n}".format(1234567890) '1,234,567,890' However, surprisingly, this won’t work for every

How to use the date format that has been setup as default in Settings?

十年热恋 提交于 2019-12-12 10:39:24
问题 As you probably know, you can setup date format in the Settings of an Android device. In code how do we make sure that we use that format for date display? 回答1: Try android.text.format.DateFormat , notably getDateFormatOrder() to get the user's preferred date format. 回答2: You can retrieve both the date format as well as the time format like this: DateFormat timeFormat; DateFormat dateFormat; dateFormat = android.text.format.DateFormat.getDateFormat(context); timeFormat = android.text.format

Python 3 UnicodeEncodeError: 'ascii' codec can't encode characters

爱⌒轻易说出口 提交于 2019-12-12 08:43:30
问题 I've just started to learn Python but I already ran into troubles. I have a simple script with just one command: #!/usr/bin/env python3 print("Příliš žluťoučký kůň úpěl ďábelské ódy.") # Text in Czech When I try to run this script: python3 hello.py I get this message: Traceback (most recent call last): File "hello.py", line 2, in <module> print("P\u0159\xedli\u0161 \u017elu\u0165ou\u010dk\xfd k\u016fn \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy.") UnicodeEncodeError: 'ascii' codec can't encode

In Java, why does the decimal separator follow the Locale's language, not its country, and, more importantly, how does one override it?

自古美人都是妖i 提交于 2019-12-12 08:34:47
问题 I'm working on an international project and have observed that, in Java, the choice of the decimal separator is based on the Locale's language, not its country. For example: DecimalFormat currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("it","IT")); System.out.println(currencyFormatter.format(-123456.78)); currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("en","IT")); System.out.println(currencyFormatter.format(-123456.78)); produces the following

Force Android DateUtils.getRelativeDateTimeString() to ignore the device locale?

孤街浪徒 提交于 2019-12-12 08:23:12
问题 I've found using the android.text.format.DateUtils relative APIs that return values like "yesterday" or "2 hours ago" very nice - but my app does not support every language Android does. So, I default to English, but for every language I don't support, the relative string shows in the device's setting. For example, like: Last attempt: hace 11 minutos. I'd like to make the API call default to English for any languages I don't support. However, I don't see anywhere to set the Locale for the API

Android user-set Locale always get reset after onCreate?

柔情痞子 提交于 2019-12-12 08:19:01
问题 I want to have a configurable language settings in my app. So, in onCreate of my activity, I call Resources.updateConfiguration with the new locale. However, after onCreate (at some time, I can't find it when), the locale is set back to the default locale. On the code example below, the strings shown in the main layout (as inflated by setContentView) shows the "in" language version, BUT when I press the menu button, on which onCreateMenu is called, the strings is taken from the "en" (default)

Language change issue after updating to androidx.appcompat:appcompat:1.1.0

狂风中的少年 提交于 2019-12-12 07:53:46
问题 The link of the latest app-compat which is 1.1.0. After upgrading my app to the latest app-compat my language settings stopped working for phones below API 24 (roughly, doesn't work on API 21 and below for sure). For API 24 and above, I have used the ContextWrapper and set the locale hence works. My question is if the androidx.appcompat:appcompat:1.1.0 is the stable version why does it work for me in alpha and beta versions unlike the others here & the questions which I have tried. After