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

Added support for i18n (ERB templates only) #37

Merged
merged 1 commit into from
Oct 8, 2016

Conversation

bogdanRada
Copy link
Contributor

@bogdanRada bogdanRada commented Jun 23, 2016

I added support for I18n internationalization as discussed here: #35 . This should fix this issue #9

This allows also to inject into the maintenance page additional helpers needed for internationalization or using sprockets (if needed) . Although they will have to add those gems themselves to their Gemfile.

E.g configuration for Rack (Or Rails) :

Turnout.configure do |config|
  config.i18n.load_path = Dir[File.join(config.app_root, 'config', 'locales', '*.yml')]
  config.i18n.additional_helpers = [MyAwesomeModule]
end

The additional helpers was added so that depending on preferences and framework, each can add their one modules for handling either I18n translations or use sprockets helpers for rendering css files and js files.

Let me know what you think. Thank you very much.

Maybe could be simplified even more. Let me know if you have suggestions

@bogdanRada
Copy link
Contributor Author

bogdanRada commented Jun 23, 2016

I should probably add an option to enable it or disable this functionality and make it disabled by default.
Will also add some tests and also some documentation will need updated. But wanted to get some early feedback on this before i make all the changes.

@bogdanRada
Copy link
Contributor Author

bogdanRada commented Jun 23, 2016

And i added also support for HTTP_ACCEPT_LANGUAGE header. If the header specifies a locale that is available from the ones provides, will use that, otherwise the default locale. I should probably also add an option to disable this or enable this and make it disabled by default or i can remove it if you think will overly complicate things and will be harder to maintain.

@bogdanRada
Copy link
Contributor Author

bogdanRada commented Jun 24, 2016

I added two more options, so in the end this is the full default configuration :

Turnout.configure do |config|
  config.i18n.load_path = []
  config.i18n.railties_load_path = []
  config.i18n.additional_helpers = []
  config.i18n.fallbacks = [I18n::Backend::Fallbacks]
  config.i18n.enabled = false
  config.i18n.use_language_header = false 
end

If you need i18n , you have to enable it by setting the "enabled" option to true , and also the support for language header is disabled by default. Any other configurations can be added , and will be directly set on I18n module.

For example, setting the default locale can be done with

 config.i18n.default_locale = :en

Although this is not set by default in this gem, any additional configuration added for i18n will be directly set on I18n module . Further customization can be found here: http://guides.rubyonrails.org/i18n.html

I haven't set them with values by default in this gem because that is a matter of preference so anyone can customize how they want to work with i18n.

@bogdanRada bogdanRada changed the title i18n support . Tested with both Rack and Rails applications, seems to work ok (works only with erb pages) i18n support (ERB templates only) Jun 28, 2016
@bogdanRada bogdanRada changed the title i18n support (ERB templates only) Added support for i18n (ERB templates only) Jun 28, 2016
@bogdanRada
Copy link
Contributor Author

bogdanRada commented Jul 18, 2016

can someone take a look? it's almost a month since last comment .

I have tested this with both Rails and Rack based applications and for me works perfectly. But let me know if you have any suggestions or something can be improved. I am opened to any suggestions.

@bogdanRada
Copy link
Contributor Author

bogdanRada commented Aug 11, 2016

any news on this? I still got no feedback in two months :(

@bogdanRada bogdanRada mentioned this pull request Aug 25, 2016
@zenzei
Copy link

zenzei commented Sep 14, 2016

Hi @bogdanRada, I'm interested in testing your branch with this changes, do you think will allow to use some of the available rails helpers (like image_path or javascript_include_tag) in the maintenance.html.erb? Thanks!

@bogdanRada
Copy link
Contributor Author

bogdanRada commented Sep 14, 2016

VHello ,
That is great . Yes that is possible but You will have to add the helper modules în the additional_helpers array like i showed above.

I am în vacation right now and will be out of town for a week but let me know if there are any issues and will try to resolve them or answer your questions ( if You will have some more additional questions) after that time.

Happy testing :)

@bogdanRada
Copy link
Contributor Author

@adamcrown ,. Can You please review this pull request? It's been a long time sincer i opened this pull request ( more than 3 months ) . Please. Thank You very much

end
end

def inheritable_copy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method maybe left over from some older code? I couldn't find anywhere that it was being used. Please let me know if I'm missing anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in the Turnout::Internationalization , method i18n_config
This is needed in case someone will use the configuration like this:

Turnout.config.i18n = { some_key:  :value  } 

The code will transform the hash into a instance of OrderedOptions class to preserve compatibility with the existing code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, good to know. It just wasn't immediately obvious and I wanted to make sure it was there for a reason.

@adamcrown
Copy link
Collaborator

I apologize that it's take me so very long to get to this. I've been busy and have had less time to work on my open source projects. I'll try to do better from here on out.

It all really looks good. Thanks for putting so much work into this. I had one small comment in the code, but not a big deal.

If you do have time to write some tests and documentation, that would really be appreciated. I'd especially like to see that we throw a lot of different Accept-Language headers at it to make sure it won't cause any errors.

Thanks again, so much. And sorry the very late response.

@bogdanRada
Copy link
Contributor Author

Thanks a lot. I will add tests and documentation în as soon as possible. I think that code You were referring to is a leftover but i have to check that . I am on my phone right now.
Will let You know when i finish the tests and documentation. Thanks a lot :)

@bogdanRada
Copy link
Contributor Author

@adamcrown , please check again this pull request. I added tests, the coverage is now at 98.95%
Let me know if anything else needs changing or refactored or maybe more tests.

Not sure though about documentation...what needs to be done. Maybe a wiki page? Please let me know and i will work on that too. Thanks.

@adamcrown
Copy link
Collaborator

Looks good. Thanks for adding all the tests. That give me a lot more confidence in adding it since it's so much added code.

I think a Wiki page with maybe a link from the README would be great. Thanks.

@adamcrown adamcrown merged commit 24815d2 into biola:master Oct 8, 2016
@bogdanRada
Copy link
Contributor Author

Thanks a lot :) i will try to create a wiki page this week.

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.

3 participants