Langstrings Options

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Langstrings Options

Postby decompile » Sat Dec 19, 2015 2:56 pm

Hey,

I found Langstrings today and must say its so easy to use but i have one question to it.

strings.ini
[EliminatedTarget]
en = Eliminated $target with $weapon


Syntax: Select all

strings = LangStrings('strings')
message = (strings["EliminatedTarget"][language]


But how can i replace the $target and $weapon ?

This example was taken from ES
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sat Dec 19, 2015 4:44 pm

Syntax: Select all

strings['EliminatedTarget'].get_string(language=None, target='foo', weapon='bar')
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sat Dec 19, 2015 5:33 pm

Thank you perfect.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sat Dec 19, 2015 5:37 pm

L'In20Cible wrote:

Syntax: Select all

strings['EliminatedTarget'].get_string(language=None, target='foo', weapon='bar')


Thank you perfect.

Is it also possible to use the keywords from list?

for example

if the options are:

Syntax: Select all

options = ["target" : "joker", "weapon" : "AK47"]
strings['EliminatedTarget'].get_string(language=None, options)


And can i still use $target and $weapon for my keywords in the ini or is there another syntax for that?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sat Dec 19, 2015 7:53 pm

Well, no. You cannot assign them an order cause that can change from a language to another and they need to be translated wherever they are in the sentence so they have to be named keywords.

Actually, there is 2 styles currently implemented to convert keywords and this is going to change. The Template.substitute way (which is the one using the $ prefix) is going to be removed. You will have to use the str.format pattern (minus the indexing part like I mentionned above) so your file will become:

Syntax: Select all

[EliminatedTarget]
en = Eliminated {target} with {weapon}


Anyways, you could also use ** combined with a dict storing your keywords:

Syntax: Select all

keywords = {'target': 'foo', 'weapon': 'bar'}
string = strings['EliminatedTarget'].get_string(language, **keywords)


Since you mentionned list, you could always use pairs with the dict constructor:

Syntax: Select all

keywords = dict([('target', 'foo'), ['weapon', 'bar')])

But heh, prefer the dictionary.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 131 guests