Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Changing a cross-reference during generation(For purposes of internationalization, switch the cross-reference to a string to one appropriate for the user's human language)
Changing a cross-reference during generation [message #962326] Mon, 29 October 2012 02:03
Kokongi Nei is currently offline Kokongi NeiFriend
Messages: 5
Registered: July 2012
Junior Member
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:

package product.manual
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"
etc. etc.

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, 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"
etc. etc.

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:

import product.manual.*

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 For paragraph 1, the reference points to product.manual.safetywarning.p1, but I also want to get

Note that we do not know ahead of time which languages the user will pick.

Thanks in advance for assistance!
Previous Topic:Adding API to access ImportManager or to add imports to ITreeAppendable
Next Topic:Creating an xbase Project
Goto Forum:

Current Time: Wed Apr 14 18:22:34 GMT 2021

Powered by FUDForum. Page generated in 0.01925 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top