Page 1 of 1

Translation question

Posted: Mon Mar 19, 2018 6:55 am
by HansBr
Hello,
I write my game in German, because it is easier for me to translate than to be creative in a foreign language. For the most part translation works well. Now I got a little problem. I have some passages where text needs to be inserted in an other string. Something like this:

Code: Select all

	$ insert = getText(1)
	a "german [insert] german"
in the translation file that would look like:

Code: Select all

# a "german [insert] german"
a "english [insert] english"
getText(x) reads constant text from something like

Code: Select all

python:
	CONST = { 1:_("abc"), 2:_("def")}
	def getText(i):
		return CONST[i]
There is a bit more to it, but that should be enough to showcase the translation part. I do not change the text string in any way in getText().

Of course there is a appropriate translation file with

Code: Select all

	old "abc"
	new "uvw"
	
	old "def"
	new "xyz"
But when I run the translated version of the game, the resulting string is:

"english abc english" It should be "english uvw english"

What am I doing wrong?

Re: Translation question

Posted: Mon Mar 19, 2018 7:14 am
by HansBr
Found it. I need to add !t to insert. It is [insert!t].
Sorry for not searching enough before asking.

Re: Translation question

Posted: Mon Mar 19, 2018 11:06 am
by HansBr
Me again.
It does not work for more complex translations.

Code: Select all

    a = someFunction(__("german {0} german {1} german").format(subst1, subst2))
still always substitutes the German parts. Double underscores do not help. !t gives the following error:

Code: Select all

   ValueError: Unlnown conversion specifier t
the exact code in this case is deep within a python block:

Code: Select all

                          menulist.append((__("Du könntest {0} mit {1} verschönern").
                                            format(target,itemName),
                                         (hooklist[h], itm["item"])))
A explicit renpy.translate() function would be nice, but I can not find anything like that. Am I missing something?

Re: Translation question

Posted: Mon Mar 19, 2018 12:27 pm
by Remix
renpy.substitute() is likely what you are after...

Code: Select all

menulist.append(_("Du könntest {0} mit {1} verschönern").format(
    renpy.substitute(target),
    renpy.substitute(itemName)), ...
Would/should pre-translate the target and itemName before pyFormatting them into the _() wrapped translation string

Re: Translation question

Posted: Mon Mar 19, 2018 1:04 pm
by HansBr
Thank you.
renpy.substitute() was exactly the function I was looking for.

Re: Translation question

Posted: Sat Mar 24, 2018 2:41 am
by lemmatree
I would try with the suggestion as well. I am planning to do the Chinese translation.