nodes in localized Blender versions

What’s the best approach to working with localized Blender versions and their localized naming of nodes and node inputs etc?

Accessing the Diffuse BSDF node in a newly created material, you do

node_tree.nodes['Diffuse BSDF'].

However, in Portuguese, the node would be called ‘BSDF - Difuso’ and so the above would fail.

Similarly, the following would fail as well:

diffusenode.inputs['Roughness']'

Because it’s actually called ‘Rugosidade’ in Portuguese.

Am I missing something obvious? I can’t be expected to cover all language cases?

I’d appreciate any input!

You can get the UI language by doing

bpy.context.user_preferences.system.language

Not sure how you would localize everything though. You could just have a few supported languages and get the user language, then change the strings based on that.

Edit: Actually a better method, do node_tree.nodes[index].type and you’ll get a name like “BSDF_DIFFUSE”, that doesn’t change with the user language.

Thanks for the input! I thought about both of these before, but neither really helps. Checking for the language would still require I manually support all kinds of languages and their different terms.

Iterating over all nodes and checking for their types may work for nodes themselves, but this doesn’t work for their inputs. Also, iterating till you find a type seems really inefficient compared to straight selecting nodes (by name). It also doesn’t provide a way to distinguish between nodes of the same type.

You can of course also address nodes and their inputs via their indices, but that’s far from ideal and error prone.

I’m quite surprised there doesn’t seem to be a good way to deal with this.

The best approach is probably to not rely on any existing nodes (as in a newly created material) and instead always create all nodes from scratch. Unfortunately that still doesn’t take care of node input names.

Thanks for the input! I thought about both of these before, but neither really helps. Checking for the language would still require I manually support all kinds of languages and their different terms.

Iterating over all nodes and checking for their types may work for nodes themselves, but this doesn’t work for their inputs. Also, iterating till you find a type seems really inefficient compared to straight selecting nodes (by name). It also doesn’t provide a way to distinguish between nodes of the same type.

You can of course also adress nodes and their inputs via their indices, but that’s far from ideal and error prone.

I’m quite surprised there doesn’t seem to be a good way to deal with this.

The best approach is probably to not rely on any existing nodes (as in a newly created material) and instead always create all nodes from scratch. Unfortunately that still doesn’t take care of node input names.

Maybe playing around with bpy.app.translations, and the modules in the scripts/modules/bl_i18_utils/* ?!
I never digged that much into the translations part of blender, but I think you can get a translation to the default ‘en-us’ from the active language.

Thanks, I’ve looked but didn’t find much. Since blender is able to do the mapping for different languages, it would be great to have a function to do the reverse mapping.

You can select inputs by index instead of name: