Script work with several Languages

Hello everyone, i just want to ask if there is a way to make a dynamo script works in several language ? for example when i use a parameter name string in french and then i need yo use this script on an english version without changing the parameter name to english manually ! Thank you.

You could review your options after you get the Revit language as shown here:

That said if you’re doing a workflow which frequently works across languages within your office you may want to consider adding a UI element to allow the user to select the parameter they want to work with directly. That or make a list of what the parameter name should be in every language you use, and use that as a dictionary to get the right result.

I believe the Revit language packs may also allow you to resolve this in another way.

1 Like

heres a code block example of how you could define a list of parameter strings in two languages then you could call these strings using the new definition

def params (num) {
Translated_Params = {
{“english0”,“french0”},
{“english1”,“french1”},
{“english2”,“french2”}
};
//change language index once
language = 1;
return = Translated_Params[num][language];
};
//call strings
params(0…2);

http://dynamoprimer.com/en/07_Code-Block/7-4_functions.html

2 Likes

Why don’t you address parameters by their id?
Examples can be found @ buildingcoder

2 Likes

@JacobSmall @adam_bear1 @Peter_Kompolschek thank all of you mates i will try those solutions and give you feedback.

If they are built in parameters with a consistent ID than the method @Peter_Kompolschek linked is likely best.

If the IDs change based on project workflow than the dictionary illustrated by @adam_bear1 is likely best.

If there are neither standard names nor standard IDs than go the UI route for now, and discuss standardizing the workflow long term.

2 Likes

@JacobSmall i asume multilingual Shared parameters are out of @adam_bear1 s scope.

1 Like

slight improvement based on string rather than integer

def params (str) {
Translated_Params = {
{"english0","french0"},
{"english1","french1"},
{"english2","french2"}
};
//change language index once
language = 1;

//search for parameter
contains = List.ContainsItem(Translated_Params<1L>, str);
indices = List.AllIndicesOf(contains, true);

return = Translated_Params[indices][language];
};
//call strings
params({"english0","english1","english2"});
1 Like

another slight improvement to run on partial strings

def params (str) {
Translated_Params = {
{"english0","french0"},
{"english1","french1"},
{"english2","french2"}};
//change language index once
language = 1;

//search for parameter
str_contains = String.Contains(Translated_Params, str, false);
index_str = List.AllIndicesOf(str_contains@-2<1>, true);
empty = List.IsEmpty(index_str<1L>);
index_false = List.AllIndicesOf(empty, false);
first = List.FirstItem(index_false);

return = Translated_Params[first][language];
};
//call strings
params({"ish","lish1","glish2"});
1 Like