Permalink
Browse files

fixes #2269 - Add gettext framework to foreman.

This patch adds a gettext based localization framework to the Foreman. This is done by adding the fast_gettext and gettext_i18n_rails gems along with their depdencies. An example translation is done to the login page and the users controller.

Next steps, once this patch is merged, is to begin to internaitonalize new pages and pages which are touched during enhancements. Then, the strings can be exported to a translation tool such as transifex or zanata.
  • Loading branch information...
1 parent 7cddc10 commit 69be16415a83343a9d399f1e77e22971b6b9cf9e @bkearney bkearney committed with ohadlevy Mar 1, 2013
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
# standard layout to all controllers
helper 'layout'
+ before_filter :set_gettext_locale
before_filter :require_ssl, :require_login
before_filter :session_expiry, :update_activity_time, :unless => proc {|c| c.remote_user_provided? || c.api_request? } if SETTINGS[:login]
before_filter :set_taxonomy, :require_mail, :check_empty_taxonomy
@@ -90,7 +90,7 @@ def login
user = User.try_to_login(params[:login]['login'].downcase, params[:login]['password'])
if user.nil?
#failed to authenticate, and/or to generate the account on the fly
- error "Incorrect username or password"
+ error _("Incorrect username or password")
redirect_to login_users_path
else
#valid user
@@ -110,7 +110,7 @@ def logout
flash.keep
else
session.clear
- notice "Logged out - See you soon"
+ notice _("Logged out - See you soon")
end
redirect_to login_users_path
end
@@ -1,9 +1,9 @@
<%= form_tag login_users_path, :id => "login-form", :class => "form-vertical" do %>
<%=image_tag("foreman_large.png", :class=>"login-large-logo") %>
- <%= label_tag "login[login]", "Username" %>
+ <%= label_tag "login[login]", _("Username") %>
<%= text_field :login, :login %>
- <%= label_tag "login[password]", "Password" %>
+ <%= label_tag "login[password]", _("Password") %>
<%= password_field_tag "login[password]" %>
<%= submit_tag("Login &#187;".html_safe, :class => "btn btn-primary fr", :disable_with => "Please wait...") %>
<% end %>
View
@@ -7,4 +7,7 @@
gem 'pry'
gem "term-ansicolor"
# gem 'rack-mini-profiler'
+
+ # for generating i18n files
+ gem 'gettext', '>= 1.9.3', :require => false
end
View
@@ -0,0 +1,5 @@
+group :i18n do
+ gem 'fast_gettext', '>=0.4.8'
+ gem 'gettext_i18n_rails'
+ gem 'i18n_data', '>= 0.2.6', :require => 'i18n_data'
+end
@@ -0,0 +1,8 @@
+require 'fast_gettext'
+require 'gettext_i18n_rails'
+
+locale_dir = File.join(File.dirname(__FILE__), '..', '..', 'locale')
+
+FastGettext.add_text_domain 'app', :path => locale_dir, :type => :po
+FastGettext.default_available_locales = ['en','ja'] #all you want to allow
+FastGettext.default_text_domain = 'app'
View
@@ -0,0 +1,9 @@
+require "fast_gettext"
+require "gettext_i18n_rails"
+require "gettext_i18n_rails/tasks"
+
+namespace :gettext do
+ def files_to_translate
+ Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml}")
+ end
+end
View
@@ -0,0 +1,30 @@
+#
+# Template file for strings which can be localized in the
+# Foreman Application.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: version 0.0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-03-03 11:37-0500\n"
+"PO-Revision-Date: 2013-03-01 15:45-0500\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
+
+msgid "Incorrect username or password"
+msgstr ""
+
+msgid "Logged out - See you soon"
+msgstr ""
+
+msgid "Password"
+msgstr ""
+
+msgid "Username"
+msgstr ""
View
@@ -0,0 +1,31 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: version 0.0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-03-03 11:37-0500\n"
+"PO-Revision-Date: 2013-03-01 15:45-0500\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
+
+msgid "Incorrect username or password"
+msgstr ""
+
+msgid "Logged out - See you soon"
+msgstr ""
+
+msgid "Password"
+msgstr ""
+
+msgid "Username"
+msgstr ""
View
@@ -0,0 +1,30 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: version 0.0.1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-03-03 11:37-0500\n"
+"PO-Revision-Date: 2013-03-01 15:45-0500\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
+
+msgid "Incorrect username or password"
+msgstr ""
+
+msgid "Logged out - See you soon"
+msgstr ""
+
+msgid "Password"
+msgstr "パスワード"
+
+msgid "Username"
+msgstr "ユーザー名"

0 comments on commit 69be164

Please sign in to comment.