[Pas2js] resourcestrings structure
warleyalex
warleyalex at yahoo.com.br
Fri Aug 9 16:39:22 CEST 2019
Basically i18next, looks for the attribute "data-i18n" and replaces the texts
in one go using DOM manipulations.
see in action:
https://pas2js.github.io/index.html
Yeash, so the experiment is basically
I'm trying to play with pas2js "resourcestrings" with the external lib
"i18next" to build multi-lingual using DOM Manipulating.
The idea is to keep a series of "language" local JSON files separared, we
need to generate these files:
- en.jrs
- fr.jrs
- it.jrs
- br.jrs
Based on the units:
---------------------
unit en;
{$mode objfpc}
interface
resourcestring
Good_bye = 'Good bye! $t(menu.country)';
Hello = 'Hello! $t(menu.country)';
Selectyourlanguage = 'Select your language: $t(menu.country)';
country = 'England';
implementation
end.
-----------------------
unit fr;
{$mode objfpc}
interface
resourcestring
Good_bye = 'Au revoir ! $t(menu.country)';
Hello = 'Bonjour ! $t(menu.country)';
Selectyourlanguage = 'Sélectionner votre langage: $t(menu.country)';
country = 'France';
implementation
end.
-----------------------
unit it;
{$mode objfpc}
interface
resourcestring
Good_bye = 'Arrivederci! $t(menu.country)';
Hello = 'Buongiorno! $t(menu.country)';
Selectyourlanguage = 'Seleziona la tua lingua: $t(menu.country)';
country = 'Italy';
implementation
end.
-----------------------
unit br;
{$mode objfpc}
interface
resourcestring
Good_bye = 'Oi! $t(menu.country)';
Hello = 'Olá! $t(menu.country)';
Selectyourlanguage = 'Selecione seu idioma: $t(menu.country)';
country = 'Brasil';
implementation
end.
*****************************
... so we've generated 4 files:
pas2js -Jrunit en.pas -B
pas2js -Jrunit fr.pas -B
pas2js -Jrunit it.pas -B
pas2js -Jrunit br.pas -B
**********************************
{
"it" : {
"Good_bye" : "Arrivederci! $t(menu.country)",
"Hello" : "Buongiorno! $t(menu.country)",
"Selectyourlanguage" : "Seleziona la tua lingua: $t(menu.country)",
"country" : "Italy"
}
}
------
{
"fr" : {
"Good_bye" : "Au revoir ! $t(menu.country)",
"Hello" : "Bonjour ! $t(menu.country)",
"Selectyourlanguage" : "Sélectionner votre langage: $t(menu.country)",
"country" : "France"
}
}
-------
{
"en" : {
"Good_bye" : "Good bye! $t(menu.country)",
"Hello" : "Hello! $t(menu.country)",
"Selectyourlanguage" : "Select your language: $t(menu.country)",
"country" : "England"
}
}
------
{
"br" : {
"Good_bye" : "Oi! $t(menu.country)",
"Hello" : "Olá! $t(menu.country)",
"Selectyourlanguage" : "Selecione seu idioma: $t(menu.country)",
"country" : "Brasil"
}
}
------
*****
pas2js declares for each of the .jrs an object which is basically the
namespace "unit Name", following this structure:
{
%unitName% : {
%key% : %value%,
}
}
However, we can not play i18next lib with pas2js/resourcestrings to perform
multi-lingual idea.
it works as expected if we change manually all the 4 .jrs files and change
the object/namespace to have multi-lingual feature.
{ filename: en.jrs }
{
"menu" : {
"Good_bye" : "Good bye! $t(menu.country)",
"Hello" : "Hello! $t(menu.country)",
"Selectyourlanguage" : "Select your language: $t(menu.country)",
"country" : "England"
}
}
ahm, the command line to set manually the namespace, I think:
pas2js -Jrunit en.pas -B -NS"menu"
pas2js -Jrunit fr.pas -B -NS"menu"
pas2js -Jrunit it.pas -B -NS"menu"
pas2js -Jrunit br.pas -B -NS"menu"
Yeah, I agree: "the pas2js compiler creates the internal structure. You must
follow this structure when
translating. How you get your translations, is entirely up to you."
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list