2

We generate translation files with placeholders that are populated later, but have a problem regarding words in languages that modify the preceding word.

For instance, we've written a translation template which looks like this:

because of %name%, you.....

This is problematic because in French, the translation 'of' differs if the %name% begins with a vowel or not.

For instance, if the person was Andy, it should be:

d' Andy

Whereas for Steve it would be:

de Steve

What's the best way of handling this case?

I can see similar problems have been solved regarding the English indefinite article (a vs an) here, but I'm wondering if there is a smarter way of doing it rather than a custom filter for each situation we come up against (we're in many languages and I suspect other similar problems will come up as we expand our languages).

(I'm also working on getting an entirely different translation which would be ideal!)

Community
  • 1
  • 1
edhgoose
  • 887
  • 8
  • 26
  • Add an if control in your twig template and check if the [name starts by a vowel](http://stackoverflow.com/questions/15600626/begins-with-in-twig-template) – Answers_Seeker Jul 20 '15 at 16:33
  • You would also have to remove the space between the apostrophe and the name – AntoineWDG Jul 20 '15 at 16:57
  • Furthermore, while your solution technically works, what I'm trying to avoid is a situation where we have 'if name starts with vowel && french do X, if name starts with A && Spanish, do Y and so on and so forth.' – edhgoose Jul 20 '15 at 17:24
  • @edhgoose there is no "built-in" solution for that if that's what you're aiming at. You're going to have to either place if-else in template or create custom twig extension – Igor Pantović Jul 20 '15 at 18:35

1 Answers1

0

The answers you seek lie in extending the Translator class itself.

This question shows how to accomplish extending the translator in a similar way necessary to add this functionality. You can simply use the idea of translation suffixes to add the proper translations to your translation catalog then build up logic in the trans() function to look at the locale and the translation id (string you are translating) passed to add the correct suffix and arrive at the correct translation.

Community
  • 1
  • 1
Reid Johnson
  • 1,394
  • 14
  • 20