Page 1 of 1
i18n on array structure
Posted: 16 June 2022, 12:53
by Woodruff
Hi everybody,
In my
gameXXX.game.php, I send an array of array which contains strings to be translated on client-side.
Here is a simplified static example in the
getAllDatas function:
Code: Select all
$result['hand']= [
[ /* 1st card */
[
/* 1st text */
'i18n': ['str']
'str': $var; // marked earlier as translatable with clienttranslate("")
// …
],
[
/* 2nd text */
'i18n': ['str']
'str': $var2; // marked earlier as translatable with clienttranslate("")
// …
],
// …
],
[ /* 2nd card */
// …
],
// ...
]
Will this be sufficiant for the i18n system to work in that context or do I have to add something for translation to take place for the client?
Thanks for your insights!
Wood
Re: i18n on array structure
Posted: 16 June 2022, 14:58
by Tisaac
Re: i18n on array structure
Posted: 17 June 2022, 15:55
by Woodruff
Thanks Tisaac,
That is very informative, I did not know this ressounce. I think I will use some other tips presented from now on, especially the CSS flex part to replace the Stock component.
(Are you the author of that blog? Big thanks to him no matter what!)
My case does not involve text nesting (log inside log). So, if I understand well, if I summon this in js:
Code: Select all
var card_text = _(cards[i][j].str)
to directly be put inside the HTML tree with no additionnal text, that should work natively since:
- The string is declared to be translated in PHP (clienttranslate);
- The string fetched on client side will match exactly the one marked for translation.
Correct?
Re: i18n on array structure
Posted: 17 June 2022, 19:31
by Tisaac
Woodruff wrote: ↑17 June 2022, 15:55
Thanks Tisaac,
That is very informative, I did not know this ressounce. I think I will use some other tips presented from now on, especially the CSS flex part to replace the Stock component.
(Are you the author of that blog? Big thanks to him no matter what!)
My case does not involve text nesting (log inside log). So, if I understand well, if I summon this in js:
Code: Select all
var card_text = _(cards[i][j].str)
to directly be put inside the HTML tree with no additionnal text, that should work natively since:
- The string is declared to be translated in PHP (clienttranslate);
- The string fetched on client side will match exactly the one marked for translation.
Correct?
Exactly !
I created the blog, but i am not the only author, it's made by community so anyone can post one

Re: i18n on array structure
Posted: 19 June 2022, 21:50
by Woodruff
Tisaac wrote: ↑17 June 2022, 19:31
Exactly !
I created the blog, but i am not the only author, it's made by community so anyone can post one
Cool, for once, that is simple!
Thanks for the blog initiative, I may post something about ovveriding format_string_recursive for logging colored symbols in an easy way, if I have time (especially for card games; ♥ ♦ ♣ ♠ K Q J and so on…).