|Changing a cross-reference during generation [message #962326]
||Mon, 29 October 2012 02:03
| Kokongi Nei
Registered: July 2012
I am working on a project for which I have created an Xtext DSL that is a template language for generating multilingual text documents. The template DSL grammar imports another Xtext grammar that allows creation of Xtext model files that are key-value pairs. The key-value DSL has separate files (models) for each language. These are basically properties files, but with an Xtext grammar and editor. |
Users are able to request a tailored version of a document. They will be able to indicate whether they want a monolingual or bilingual version of the document generated, and which language(s) to use.
A simplified (toy) example follows:
Assume the following rule in the key-value grammar named Definitions, that is used with files of extension .mydefs:
Definition: name=QualifiedName '=' value=STRING
This allows for creation of language files such as the following:
In the file text.mydefs, there could be entries such as:
safetywarning.p1 = "Do not operate this radio near water"
safetywarning.p2 = "Do not remove screws or casing parts"
safetywarning.p3 = "Use only the power supply unit supplied"
safetywarning.p4 = "Avoid small objects and liquids from entering the product"
text.mydefs is the default language (UK English).
Other language are in separate files, with the same keys, but STRINGS that are translations of the default values.
n the file text.fr.FR.mydefs, there could be entries such as:
safetywarning.p1 = "Ne pas faire fonctionner cette radio près de l'eau"
safetywarning.p2 = "Ne pas enlever les vis ou les parties du boîtier"
safetywarning.p3 = "Utilisez uniquement le bloc d'alimentation fourni"
safetywarning.p4 = "Éviter les petits objets et les liquides de pénétrer dans le produit"
And so on, with separate models for a variety of languages.
The template grammar imports the key-value grammar Definitions as def.
It includes rules such as:
ResourceText: 'use' textRef=[def::Definition | QualifiedName];
Paragraph: 'Para' elements+=[ResourceText]* ;
A model using this grammar could contain the following:
Para use safetywarning.p1
Para use safetywarning.p2
So, by default, when the generator is called, the manual will output a document using UK English.
But, there will be a UI provided to users that allows them to indicate which languages they want included in manual for their particular use.
My question is as follows. If the user requests the default (UK English) and French (as spoken in France), how within the generator can I get the French text from the model defined in the resource text.fr.FR.mydefs? For paragraph 1, the reference points to product.manual.safetywarning.p1, but I also want to get product.manual.fr.FR.safetywarning.p1.
Note that we do not know ahead of time which languages the user will pick.
Thanks in advance for assistance!
Powered by FUDForum
. Page generated in 0.01925 seconds