Skip to content

Add i18n templates. #746

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

Closed
wants to merge 1 commit into from
Closed

Conversation

klauspost
Copy link
Contributor

All templates can now have an optional language suffix. The loader will attempt to load a template with the language specified language as an extension to the specified name. For instance "index.html" with "en" as language will attempt to load "index.html.en" first, and fall back to "template.html" if the file cannot be found.

Internationalized templates can also be dynamically included in the templates. To do this, use a the template function {{ i18ntemplate . "included.html" }}

This function will also attempt to load "included.html.en" if the language is English, and will fall back to including "included.html" if the language cannot be found.

All templates can now have an optional language suffix. The loader will attempt to load a template with the language specified language as an extension to the specified name. For instance "index.html" with "en" as language will attempt to load "index.html.en" first, and fall back to "template.html" if the file cannot be found.

Internationalized templates can also be dynamically included in the templates. To do this, use a the template function {{ i18template . "included.html" }}

This function will also attempt to load "included.html.en" if the language is English, and will fall back to including "included.html" if the language cannot be found.
@klauspost
Copy link
Contributor Author

PS. I cannot build the current "develop" branch because goagain cannot compile on Windows, so I have only tested it on 0.10.0, and manually merged the changes.

@notzippy
Copy link
Collaborator

notzippy commented Oct 3, 2014

Only comment is that you should drop the toLower in the template lookup as we are no longer doing case insensitive template lookups, see #729

@klauspost
Copy link
Contributor Author

@notzippy - that would make my change weirdly inbetween, with new code behaving another way than the existing. I think that should be done once the case change is done.

@brendensoares
Copy link
Member

@klauspost I'm not sure this is the right way to approach i18n in views. Isn't it more common to have a message lookup method to get another languages version of the content?

@ready4god2513
Copy link

@brendensoares There is already a message lookup in revel. (http://revel.github.io/manual/i18n-messages.html) This allows developers to ALSO have specific templates for different languages. This can be seen in other popular frameworks as well (http://guides.rubyonrails.org/i18n.html#localized-views)

@brendensoares
Copy link
Member

@ready4god2513 what would the different be between index.html.en and index.html.es? Wouldn't the structure of the page be the same? Seems redundant to have localized views in addition to localized message files.

@notzippy
Copy link
Collaborator

notzippy commented Oct 3, 2014

Some languages you would want represented in a different structure, some are read LTR and other RTL

@brendensoares
Copy link
Member

@notzippy as long as there is a good use case for it, then I support it 👍

I just don't have a good use case myself since I have never coded an app in a RTL language.

@klauspost can you outline a good use case from your point of view?

@ready4god2513
Copy link

Absolutely rtl is a great use case. And is something that I am actively working on. So +1 on that from me.

@klauspost
Copy link
Contributor Author

Our two current usecases are EULAs and welcome messages, that are basicly big lumps of text that it doesn't make sense for us to use the translation system for. The EULAs differ from country to country, so a simple translation isn't what we are requiring.

Another usecase is for heavily formatted text, since the current message system escapes HTML.

@brendensoares
Copy link
Member

@klauspost @ready4god2513 thanks gents. I'd like to test this out myself before we merge it, but all sounds good.

@brendensoares
Copy link
Member

brendensoares commented May 27, 2016

After talking this over with @jeevatkm we feel it would be best to not merge this PR and instead include this functionality in the upcoming pluggable template engine.

Thank you @klauspost for contributing this solution, it's a valid idea that we can use soon!

We'll leave this PR open so we don't forget it.

@pedromorgan pedromorgan closed this Mar 2, 2017
@klauspost
Copy link
Contributor Author

@pedromorgan ... you are closing because.....?

@pedromorgan
Copy link
Member

See @brendensoares comment above and pluggable template engine

@pedromorgan pedromorgan reopened this Mar 2, 2017
@notzippy notzippy modified the milestones: v0.15, v0.14 Mar 9, 2017
@shawncatz shawncatz modified the milestones: v0.16, v0.15 May 7, 2017
@notzippy
Copy link
Collaborator

Adding functionality to PR #1170, thanks for your input and design.

@notzippy notzippy closed this May 31, 2017
@klauspost klauspost deleted the i18n-templates branch January 25, 2018 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-should sooner rather than later topic-i18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants