Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Translations for the devise gem

License

NotificationsYou must be signed in to change notification settings

tigrish/devise-i18n

Repository files navigation

Further work on the devise-i18n project will be done indevise-i18n/devise-i18n. Please reference that repository for latest releases and for filing issues and pull requests.


devise-i18n

CI

Devise "is a flexible authentication solution for Rails based on Warden". Internationalization (aka i18n) is a "means of adapting computer software to different languages, regional differences and technical requirements of a target market".

Devise supports i18n in controllers, models, and in other areas, but it does not have support for internationalized views. devise-i18n adds this support. Devise also does not include the actual translations. devise-i18n does this too.

Installation

Adddevise-i18n your Gemfileafterdevise:

gem'devise'gem'devise-i18n'

Assuming you havenot previously generated Devise's views into your project, that's all you need to do. If youhave previously done this, you will need to regenerate your views (see "Customizing views" below) and then reapply whatever customizations that made you do this in the first place.

Setting your locale

You will need to set a locale in your application as described in theRails Internationalization Guide.

If you are setting the locale per request (because your application supports multiple locales), the suggested code in that guide (usingI18n.with_locale inside anaround_action) will not work properly with devise-i18n. Due toa bug in warden, some error messages will not be translated. Instead, you can set the locale in abefore_action:

before_actiondoI18n.locale=:es# Or whatever logic you use to choose.end

or in middleware:

classLocaleMiddlewaredefinitialize(app)@app=appenddefcall(env)I18n.locale=:es# Or whatever logic you use to choose.status,headers,body=@app.call(env)endend
config.middleware.use ::LocaleMiddleware

Customizing views

Thedevise:i18n:views generator will copy all devise-i18n's views to your application so that you can modify the files as you wish.

rails g devise:i18n:views

You should only do this if you really need to, though, because doing this will make it so that you won't get the updated views should they change in a future version of devise-i18n. To "uncustomize" the views, just delete them, and your app will go back to grabbing devise-i18n's default views.

If you havesimple_form in your Gemfile, this command will generate the corresponding views using the simple_form form builder.

Scoped views

If you need to use scoped views (for example, if you have different ones for users and admins), you can include the scope in this command.

rails g devise:i18n:views user

You will additionally need to generate the translations into your app per the following section and then add keys in each file for the scope you are using.

Customizing translations

If, for whatever reason, you want to change devise-i18n's translations, you can generate the locale file into your project with

rails g devise:i18n:locale it

which will generateconfig/locales/devise.views.it.yml. If you're doing this to add a missing translation or to improve an existing one, it'd be nice if you could share your suggestions with us!

Contributing translations to devise-i18n

Edit the translations directly on thedevise-i18n project on Locale.That's it!The maintainer will periodically pull translations from the Locale project and push to GitHub.

Alternately, you can create a pull request on GitHub.

In general, the tone of translations should be friendly, polite, and succinct. Certain languages (including Japanese and Korean) should use a more formal tone which is the standard for customer messages in those languages.

Copyright

Copyright (c) 2011 Christopher Dell. See LICENSE.txt forfurther details.


[8]ページ先頭

©2009-2025 Movatter.jp