Xtext with multilingual keywords - multilingual

Is it possible to create grammar with multilingual keywords? I'm implementing a dsl language with over 100 keywords, which have to be translated in multiple languages. Is there a way to achieve that with XText?
Below is an example of the dsl. The first line describes the keyword language. The second and the third line are examples of keywords in english and german
..language english
.help 'index.html'
.select '1_2'
..language german
.hilfe 'index.html'
.hole '1_2'
The dsl grammar is already defined and there are already files in different languages. Thus I have to create the editor and cannot change the grammar and the keywords.

What you ask for is certainly possible with Xtext. You can use a custom lexer yet have to make sure that you produce the very same token types as the original lexer does. You may want to check out the org.eclipse.xtext.generator.parser.antlr.ex.ExternalAntlrLexerFragment.

Related

Does Watson Language Translator service support variables which shouldn't be translated

Is there an option in Language translator to skip translation for certain words based on a regular expression or some other pattern.
For example we have some text where certain values are substituted based on a variable which we don’t want translated
"Hello $User_Name. How are you doing today?"
$User_Name should not be translated.
Is there a way to do this?

Generate english versions of same content on Drupal?

My website needs to be able to support multiple languages for multiple countries. For example, the US might have English and Spanish, while the UK might only have English. If two countries use the same language, it DOES NOT mean the content is the same.
For this reason, I decided to use the internationalization module (i18n) and I created language codes as follows:
gb-en - UK English
us-en - US English
us-es - US Spanish
I set this up with no issues, but my problem comes in with creating all the default content. For each content type, I want to:
Set the content types default language as "English"
Create translated versions of each content type for each language
I know this will mean that the Spanish content would still be in English, but it's the first step towards translating it.
What is the easiest way to create all these "default" content pages?
You could create a module implementing hook_node_insert(). This module would intercept the creation of a new node (stored with the default language) and create as many copies as needed. Each of these copies should have a different value in the field language. These copies colud be easily stored in the dabase using node_save() function.

Drupal taxonomy terms language depending - why nodes in all languages are visible?

What I want to acheive:
I have multilingual site (i18n module).
I have vocabulary named "brands" - terms of vocabulary don't need to be translated because they are the same in all languages.
I've also nodes that I can assign to languages and "brands".
In taxonomy - in multilingual options - I set this vocabulary to: Localize. Terms are common for all languages, but their name and description may be localized.
Now - the problem is - that when I enter from menu to "brands" and e.g. "volvo" in any language - list of all nodes (all translations in different languages) is shown.
I'd like to see only the nodes in language that is set.
I have other vocabulary - where terms should be translated also. I have set it to Translate. Different terms will be allowed for each language and they can be translated. and there everything works fine - depending on language.
How to acheive that with my first vocabulary?
Thank you for any suggestions.
I have set the vocabulary to Translate. Different terms will be allowed for each language and they can be translated. and duplicated each brand for each language and then updated each node - with setting term for particular language.
In my opinion this is workaround, but I couldn't find other solution.

drupal 7 taxonomy i18n is not working when editing multilingual content.I'm stock to default language

I create a taxonomy called colors.
Each of my term are translatable, in french and english.
I create a content type called product where I can associate a taxonomy color. Note that my product content type is multilingual aswell
My admin default language is french.
When I create a product,the color taxonomy is only showing in french which is my admin default language. In my mind, it's supose to be displayed within the language set in the node.
It's a problem right now because, english node is associated to french taxonomy.
Anybody know how can I resolve this issue.
Thanks a lot.
It depends on how your taxonomy was set up.
There are three different modes, beside from no-multilingual:
Localize. Terms are common for all languages, but their name and description may be localized.
Translate. Different terms will be allowed for each language and they can be translated.
Fixed Language. Terms will have a global language and they will only show up for pages in that language.
I guess colors are common for all languages, so I would recommend using the first option.
You can then translate the colors via config > translate interface.
When you chose the "localize" option you don't have duplicate colors showing up on node forms.
Update
If the terms are common for all languages but you want to add more fields to the terms, you could use localize and in addition use the entity translation module.
Entity translation allows you to translate the different fields for each term.
There are two drawbacks though:
On top of the entity translation you have to translate the terms via translate interface or else the terms will not be translated on the node-edit-forms.
You have to alter the aliases for the Terms yourself via /admin/config/search/path so the terms have different path aliases for different languages
This is of course not a good solution for user-generated terms but works if the terms are moderated.

Multiple phrases per language in cakephp

I am creating a website using CakePHP that requires translation not only into multiple languages but also multiple phrases per language depending on the type of the logged in user. This will allow the same functionality but with more formal or more friendly language without duplication.
As a very simple example:
Type 1: "Customer", "purchase","shopping cart"
Type 2: "Client", "buy", "basket"
Type 3: "User", "order","invoice"
Each of these types would be available in multiple languages.
I've got the standard localization working in CakePHP (one of the reasons I chose it!) and have the appropriate default.po files in the /Locale/[lang]/LC_MESSAGES/ directory and all is working fine there (thank you to the user who noted on this site that ger needed to be deu to work ;) ).
Before I get too far into the app I'd like to add the phrasing so I can set e.g. the language as French and phrasing as type2. If I was doing this outside of a framework I'd have a matrix look-up to find the correct string based on language and phrase keys but am unsure of how to do this within CakePHP's localization.
Currently I'm using the standard __([string]) convention but as this is early in the development cycle it would be trivial to change if necessary.
I was considering using __d([phrase],[string]) but can't see how to set this without creating my app as a plugin and then I'm back to the same problem with /Locale/
I have been unable to find any example of this in my searches on SO or the cakePHP community sites so would be grateful for any suggestions.
Is there a standard way to do this within cakePHP? if not, what would be a good "best practice" way to implement this?
Edit - following the answer below here's how it was implemented:
in /app/Locale/[lang]/LC_MESSAGES/ I created a new .po files with the new phrasing in them as phrase1.po, phrase2.po etc.
Where I set the language I also set the phrasing where the phrase file matches the name of the po file:
Configure::write('Config.language', 'deu');
Configure::write('App.langDomain', 'phrase1');
and all strings were wrapped with:
__d(Configure::read('App.langDomain', 'string')
And it just works.
Use __d() like this:
__d(Configure::read('App.langDomain'), 'Some string');
In bootstrap.php check the conditions and set App.langDomain based on whatever you need.
__d() has nothing to do with plugins, you can use it everywhere.
And alternative would be to wrap your translations with a custom method, something like
__dd(Configure::read('App.langDomain'), array('foo' => __('String1', 'bar' => __('String2'));
The array is an array of langDomain => stringForThatDomain mappings. Your __dd() method would take the one that is passed in the first argument.

Resources