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

Improve translation flexibility #877

Merged
merged 4 commits into from
May 1, 2017

Conversation

Arkkimaagi
Copy link
Contributor

As I have described in #876 the translation system could be improved with better flexibility in word reordering.

With this code, support for flexible translations can be added with a case by case approach. This change is backwards compatible and should not break existing translations. (As far as I know)

I have provided a sample translation within the default calendar module that solves Finnish language problem with the word order.

If this merge request is accepted, moving from code like this:

this.translate("RUNNING") + " " + moment(event.endDate, "x").fromNow(true)

to code like this

this.translate("RUNNING", {
  fallback: this.translate("RUNNING") + " {timeUntilEnd}",
  timeUntilEnd: moment(event.endDate, "x").fromNow(true)
})

Would allow translation like this:

"RUNNING": "Päättyy {timeUntilEnd} päästä",

to result:

Päättyy viiden minuutin päästä

while falling back to old behaviour with the fallback option given in the variables.

The new translator function checks for the variables object and if it exists, it tries to replace all the variables within the given translation template with ones found in the variables. If the translation template does not contain any variables in curly braces, it checks if there's an fallback option in the variables and uses that to generate the old style translation.

This also fixes the Finnish translation for RUNNING events. Instead of saying something like "Ongoing in 5 minutes" like the current translation says, it is fixed to "Ends in 5 minutes" in Finnish.

@MichMich
Copy link
Collaborator

Awesome work! It does need some documentation though. Could you update the Readme and Changelog? Thanks!

@Arkkimaagi
Copy link
Contributor Author

I will make my suggestion for updating these files, but it will take a couple of days to do as I'm quite busy atm.

@Arkkimaagi
Copy link
Contributor Author

Anything else missing? Please feel free to edit the documentation to your liking, I tried. ;)

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