# Get selected UI-Language in python

I work with an add on for Blender and after hours of debugging I finally found the culprit. It's the localisation. For Example:

When i add a modificator, i. e. "Smooth" it is added as "Weich" in the german localisation. So far, so good. But if the coder uses another language as the user (coder: english,user: german) in lines such as

bpy.ops.object.modifier_add(type="REMESH")

bpy.context.object.modifiers["Remesh"].mode = "SMOOTH"

you get an error, that blender can't find the keyword "Remash", which is understandable, because the correct keyword would be "Weich" if you selected the german localisation.

My questions are:

• Is there a way to list all installed localisation?
• is there a way to check for the chosen localisation at the start of a script?

• Not an answer to your question, but FYI the prefered way would be not using the operator and storing the modifier in a variable : modifier = obj.modifiers.new(type='REMESH', name="whatever") and then modifier.mode = 'SMOOTH' – Gorgious Dec 15 '20 at 13:26
• thanks, I'll try it, too. – Coder1234 Dec 15 '20 at 14:34
• Note that this isn't the only reason to avoid accessing the modifier by name. If there was already a Remesh modifier on the object, your new modifier would actually be called Remesh.001, and you'd end up changing the wrong one. In general, you should never assume that anything you create through Python actually has the name you requested, because it will be changed automatically if it clashes with an existing name. – Chris Hayes Dec 20 '20 at 21:26

Both methods are provided by Blender API.

A way to list all installed localisation

>>> bpy.app.translations.locales
('en_US', 'es', 'ja_JP', 'sk_SK', 'vi_VN', 'zh_CN', 'ar_EG', 'de_DE', 'fr_FR', 'it_IT', 'ko_KR', 'pt_BR', 'pt_PT', 'ru_RU', 'uk_UA', 'zh_TW', 'ab', 'ca_AD', 'cs_CZ', 'eo', 'eu_EU', 'fa_IR', 'ha', 'he_IL', 'hi_IN', 'hr_HR', 'hu_HU', 'id_ID', 'ky_KG', 'nl_NL', 'pl_PL', 'sr_RS', 'sr_RS@latin', 'sv_SE', 'th_TH', 'tr_TR')


A way to check for the chosen localisation

>>> bpy.context.preferences.view.language
'de_DE'

>>> bpy.context.preferences.view.use_translate_interface
True

>>> bpy.context.preferences.view.use_translate_new_dataname
True

>>> bpy.context.preferences.view.use_translate_tooltips
True