mesterlum 4 Posted December 23, 2018 Share Posted December 23, 2018 M2 Download Center This is the hidden content, please Sign In or Sign Up ( Internal ) Hello, i maked a simple script for get initial lang... the proposite is automate the choice of the languaje (for servers internationals). Unknown if there will be something similar Source: import requests class CurrentPositionForLang: # Code langs __LANGS_AVAILABLES = ("ES", "EN", "FR", "TR",) # County with lang __COUNTRY_CODES_WITH_LANG = ( ("MX", __LANGS_AVAILABLES[0]), ("US", __LANGS_AVAILABLES[1]), ("FR", __LANGS_AVAILABLES[2]), ("ES", __LANGS_AVAILABLES[0]), ("TR", __LANGS_AVAILABLES[3]) ) @staticmethod def get_lang(): lang = "US" # Default lang for errors try: r = requests.get("http://ip-api.com/json/") if r.status_code != 200: return lang countryCode = r.json()["countryCode"] for country, langCountry in CurrentPositionForLang.__COUNTRY_CODES_WITH_LANG: if countryCode == country: return langCountry # If not finded return default return lang except requests.exceptions.ConnectionError: return lang For utilicy this class only call this method: CurrentPositionForLang.get_lang() this return only String "US, ES..." If you need add more langs, in this fields add the country and the code. __LANGS_AVAILABLES = ("ES", "EN", "FR", "TR",) # County with lang __COUNTRY_CODES_WITH_LANG = ( ("MX", __LANGS_AVAILABLES[0]), ("US", __LANGS_AVAILABLES[1]), ("FR", __LANGS_AVAILABLES[2]), ("ES", __LANGS_AVAILABLES[0]), ("TR", __LANGS_AVAILABLES[3]) ) This is the standar for code countrys: https://www.ncbi.nlm.nih.gov/books/NBK7249/ 1 1 2 Link to comment Share on other sites More sharing options...
Kori 170 Posted December 23, 2018 Share Posted December 23, 2018 Who is the request.py for the libs? But nice idea import locale pprint({"Default locale": locale.getdefaultlocale(), "Default locale data": locale.localeconv()['int_curr_symbol']}) print("") print({"Current locale": locale.getlocale(), "Current locale data": locale.localeconv()['int_curr_symbol']}) print("") Link to comment Share on other sites More sharing options...
mesterlum 4 Posted December 24, 2018 Author Share Posted December 24, 2018 i do not understand buddy, if you refer for "requests" is a module from python API. But, my idea is establish initial lang automatic. 1 Link to comment Share on other sites More sharing options...
Kori 170 Posted December 24, 2018 Share Posted December 24, 2018 11 hours ago, mesterlum said: i do not understand buddy, if you refer for "requests" is a module from python API. But, my idea is establish initial lang automatic. Yes I have a Compiler for my phone and the app have many modules but not this sorry for my mistake Link to comment Share on other sites More sharing options...
mesterlum 4 Posted December 24, 2018 Author Share Posted December 24, 2018 hace 3 horas, Kori dijo: Yes I have a Compiler for my phone and the app have many modules but not this sorry for my mistake Np bro. Link to comment Share on other sites More sharing options...
Forum Moderator VegaS™ 10309 Posted December 26, 2018 Forum Moderator Share Posted December 26, 2018 Quote If you need add more langs, in this fields add the country and the code. __LANGS_AVAILABLES = ("ES", "EN", "FR", "TR",) # County with lang __COUNTRY_CODES_WITH_LANG = ( ("MX", __LANGS_AVAILABLES[0]), ("US", __LANGS_AVAILABLES[1]), ("FR", __LANGS_AVAILABLES[2]), ("ES", __LANGS_AVAILABLES[0]), ("TR", __LANGS_AVAILABLES[3]) ) You can do something like that. root/localeInfo.py Spoiler #Search for: MODE_NAME_LIST = ( PVP_OPTION_NORMAL, PVP_OPTION_REVENGE, PVP_OPTION_KILL, PVP_OPTION_PROTECT, ) #Add after: LOCALE_REGION_DICT = { 'af' : ('za',), 'am' : ('et',), 'ar' : ('ae', 'bh', 'dz', 'eg', 'iq', 'jo', 'kw', 'lb', 'ly', 'ma', 'om', 'qa', 'sa', 'sy', 'tn', 'ye'), 'be' : ('by',), 'bg' : ('bg',), 'bn' : ('bd',), 'cs' : ('cz',), 'da' : ('dk',), 'de' : ('at', 'ch', 'de', 'li', 'lu'), 'dv' : ('mv',), 'el' : ('gr',), 'en' : ('au', 'bz', 'ca', 'gb', 'ie', 'jm', 'my', 'nz', 'sg', 'tt', 'us', 'za', 'zw'), 'es' : ('ar', 'bo', 'cl', 'co', 'cr', 'do', 'ec', 'es', 'gt', 'hn', 'mx', 'ni', 'pa', 'pe', 'pr', 'py', 'sv', 'us', 'uy', 've'), 'et' : ('ee',), 'fa' : ('ir',), 'fi' : ('fi',), 'fil' : ('ph',), 'fo' : ('fo',), 'fr' : ('be', 'ca', 'ch', 'fr', 'lu', 'mc'), 'he' : ('il',), 'hi' : ('in',), 'hr' : ('ba', 'hr'), 'hu' : ('hu',), 'hy' : ('am',), 'id' : ('id',), 'ig' : ('ng',), 'is' : ('is',), 'it' : ('ch', 'it'), 'ja' : ('jp',), 'ka' : ('ge',), 'kk' : ('kz',), 'kl' : ('gl',), 'km' : ('kh',), 'ko' : ('kr',), 'ky' : ('kg',), 'lb' : ('lu',), 'lo' : ('la',), 'lt' : ('lt',), 'lv' : ('lv',), 'mi' : ('nz',), 'mk' : ('mk',), 'mn' : ('mn',), 'ms' : ('bn', 'my'), 'mt' : ('mt',), 'nb' : ('no',), 'ne' : ('np',), 'nl' : ('be', 'nl'), 'pl' : ('pl',), 'prs' : ('af',), 'ps' : ('af',), 'pt' : ('br', 'pt'), 'ro' : ('ro',), 'ru' : ('ru',), 'rw' : ('rw',), 'si' : ('lk',), 'sk' : ('sk',), 'sl' : ('si',), 'sq' : ('al',), 'sv' : ('se',), 'sw' : ('ke',), 'th' : ('th',), 'tk' : ('tm',), 'tr' : ('tr',), 'uk' : ('ua',), 'ur' : ('pk',), 'vi' : ('vn',), 'wo' : ('sn',), 'yo' : ('ng',), 'zh' : ('cn', 'hk', 'mo', 'sg', 'tw'), } Add at end of line: import requests def GetLanguage(locale_region_default = 'en'): language = locale_region_default try: request = requests.get('http://ip-api.com/json/', params=None) if request.status_code is 200: for locale_region, country_code_tuple in LOCALE_REGION_DICT.iteritems(): if request.json().get('countryCode').lower() in country_code_tuple: language = locale_region return language except requests.exceptions.ConnectionError: return language # Initialized just one time LANGUAGE = GetLanguage() How to use it: import localeInfo print localeInfo.LANGUAGE 2 Check my GitHub Profile Click to find all the threads started by me [TOOL] Text file loader + JSON Link to comment Share on other sites More sharing options...
mesterlum 4 Posted December 26, 2018 Author Share Posted December 26, 2018 hace 3 horas, VegaS™ dijo: You can do something like that. root/localeInfo.py Reveal hidden contents #Search for: MODE_NAME_LIST = ( PVP_OPTION_NORMAL, PVP_OPTION_REVENGE, PVP_OPTION_KILL, PVP_OPTION_PROTECT, ) #Add after: LOCALE_REGION_DICT = { 'af' : ('za',), 'am' : ('et',), 'ar' : ('ae', 'bh', 'dz', 'eg', 'iq', 'jo', 'kw', 'lb', 'ly', 'ma', 'om', 'qa', 'sa', 'sy', 'tn', 'ye'), 'be' : ('by',), 'bg' : ('bg',), 'bn' : ('bd',), 'cs' : ('cz',), 'da' : ('dk',), 'de' : ('at', 'ch', 'de', 'li', 'lu'), 'dv' : ('mv',), 'el' : ('gr',), 'en' : ('au', 'bz', 'ca', 'gb', 'ie', 'jm', 'my', 'nz', 'sg', 'tt', 'us', 'za', 'zw'), 'es' : ('ar', 'bo', 'cl', 'co', 'cr', 'do', 'ec', 'es', 'gt', 'hn', 'mx', 'ni', 'pa', 'pe', 'pr', 'py', 'sv', 'us', 'uy', 've'), 'et' : ('ee',), 'fa' : ('ir',), 'fi' : ('fi',), 'fil' : ('ph',), 'fo' : ('fo',), 'fr' : ('be', 'ca', 'ch', 'fr', 'lu', 'mc'), 'he' : ('il',), 'hi' : ('in',), 'hr' : ('ba', 'hr'), 'hu' : ('hu',), 'hy' : ('am',), 'id' : ('id',), 'ig' : ('ng',), 'is' : ('is',), 'it' : ('ch', 'it'), 'ja' : ('jp',), 'ka' : ('ge',), 'kk' : ('kz',), 'kl' : ('gl',), 'km' : ('kh',), 'ko' : ('kr',), 'ky' : ('kg',), 'lb' : ('lu',), 'lo' : ('la',), 'lt' : ('lt',), 'lv' : ('lv',), 'mi' : ('nz',), 'mk' : ('mk',), 'mn' : ('mn',), 'ms' : ('bn', 'my'), 'mt' : ('mt',), 'nb' : ('no',), 'ne' : ('np',), 'nl' : ('be', 'nl'), 'pl' : ('pl',), 'prs' : ('af',), 'ps' : ('af',), 'pt' : ('br', 'pt'), 'ro' : ('ro',), 'ru' : ('ru',), 'rw' : ('rw',), 'si' : ('lk',), 'sk' : ('sk',), 'sl' : ('si',), 'sq' : ('al',), 'sv' : ('se',), 'sw' : ('ke',), 'th' : ('th',), 'tk' : ('tm',), 'tr' : ('tr',), 'uk' : ('ua',), 'ur' : ('pk',), 'vi' : ('vn',), 'wo' : ('sn',), 'yo' : ('ng',), 'zh' : ('cn', 'hk', 'mo', 'sg', 'tw'), } Add at end of line: import requests def GetLanguage(locale_region_default = 'en'): language = locale_region_default try: request = requests.get('http://ip-api.com/json/', params=None) if request.status_code is 200: for locale_region, country_code_tuple in LOCALE_REGION_DICT.iteritems(): if request.json().get('countryCode').lower() in country_code_tuple: language = locale_region return language except requests.exceptions.ConnectionError: return language # Initialized just one time LANGUAGE = GetLanguage() How to use it: import localeInfo print localeInfo.LANGUAGE good job my friend, and thanks for complete the script for clients. Link to comment Share on other sites More sharing options...
Recommended Posts