Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionals #323

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conditionals #323

wants to merge 4 commits into from

Conversation

Drizin
Copy link

@Drizin Drizin commented Dec 5, 2016

With conditionals we can use a single nugget tag and have different translations according to the value of parameters.:

[[[%0_PRODUCTS_ADDED_TO_ORDER]]] -> 
"%0{0:No products were added|1:1 product was added|%0 products were added} to your order" 

e.g.: [[[This %0 allows %1 to have %2|||regex|||nuggets|||(((recursive %0|||(((parameters///comment3)))///comment2)))///comment1]]]  -> This regex allows nuggets to have recursive parameters
…de other nuggets): README, Unit test and bug fix.
With **conditionals** you can use a single nugget tag and have different translations according to the value of parameters.

[[[%0_PRODUCTS_ADDED_TO_ORDER]]] -> "%0{0:No products were added|1:1 product was added|%0 products were added} to your order"

[[[DEAR_SIR_OR_MADAM|||@ViewBag.Gender]]] -> "Dear %0{M:Sir|F:Madam|user}"
@tOmoness tOmoness mentioned this pull request Dec 5, 2016
@turquoiseowl
Copy link
Owner

If I understand this code correctly, you want to move some conditional logic from outside the nugget into the nugget? Can you elaborate on the benefit of doing that? Thanks.

@turquoiseowl
Copy link
Owner

It's Monday morning and I'm struggling to understand what you mean in your examples, for instance:

[[[%0_PRODUCTS_ADDED_TO_ORDER]]] -> 
 "%0{0:No products were added|1:1 product was added|%0 products were added} to your order" 

Can you help?

@Drizin
Copy link
Author

Drizin commented Dec 5, 2016

No problem, actually I didn't make myself clear on this.
These conditional patterns are based on Ruby i18n inflector (http://www.rubydoc.info/gems/i18n-inflector/2.6.6). Quoting from their documentation:

can be used if there is a need to be strict and/or to use the same token names but assigned to different kinds. Example:
welcome: "Dear @gender{f:Lady|m:Sir|n:You|All}"

It follows a simple pattern: @variable { possiblevalue1:text | possiblevalue2: text | .... | default text)
Something like:

switch(@gender)
{
   case "f": return "Lady";
   case "m": return "Sir";
   case "n": return "You";
   default: return "All";
}

This example is very simple, and one could just have different nuggets for each possible text. However, when it comes to inflections that do not exist in in your base language (e.g. gender inflection does not exist in English) then conditionals are necessary (#323) which allied to extension attributes (#324) allow you to make whatever flections are needed.

In other words, one may always have a nugget for every possible sentence:
[[[Your order has been saved]]]
[[[Your invoice has been saved]]]
Translations would be specific for each different nugget, and although cumbersome it works.

However, if someone has a more reusable structure like
[[[Your %0 has been saved|||(((invoice)))]]]
some languages couldn't translate that, because depending on the argument %0 the translation should be different. That's what inflectors are for - they are used to choose the correct inflection when verbs/adjetives/articles/etc depend on a dynamic argument.

In portuguese language for example, invoice (nota fiscal) is a feminine noun, and order (pedido) is a masculine noun. So the translations depend on that attribute (the gender of the argument):
"Seu %0 foi salvo" (masculine arguments)
"Sua %0 foi salva" (feminine arguments).

Does that make sense?

Many languages have even more complex inflections (multiple types of plural, more than 2 genders), and I think #324 could cover all that. In other words #323 alone could be described as you did (moving conditional logic from outside the nugget to inside it), but #324 covers a real word requirement for inflections.

Hope it's more clear now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants