Skip to content

Commit

Permalink
Internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Remchi committed Mar 29, 2013
1 parent a65897d commit 41c81a1
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ gem 'jquery-rails'
gem 'sorcery', git: "https://github.com/NoamB/sorcery"
gem 'cancan'

gem 'i18n-js'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ GEM
hike (1.2.1)
httpauth (0.2.0)
i18n (0.6.4)
i18n-js (2.1.2)
i18n
jbuilder (1.0.2)
activesupport (>= 3.0.0)
jquery-rails (2.2.1)
Expand Down Expand Up @@ -142,6 +144,7 @@ DEPENDENCIES
cancan
coffee-rails (~> 4.0.0.beta1)
handlebars_assets
i18n-js
jbuilder (~> 1.0.1)
jquery-rails
rails (= 4.0.0.beta1)
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/app/buggy.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#= require_tree ./templates
#= require_tree ./views
#= require_tree ./routers
#
I18n.defaultLocale = "en"
I18n.locale = "ru"

Handlebars.registerHelper "t", (msg) -> I18n.t msg

window.App =
Routers: {}
Expand Down
8 changes: 4 additions & 4 deletions app/assets/javascripts/app/templates/header.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div class="navbar-inner">
<a href="/" class="brand">Buggy</a>
<a href="/" class="brand">{{t "brand"}}</a>
<ul class="nav pull-left">
<li><a href="/#projects">Projects</a></li>
<li><a href="/#projects">{{t "projects"}}</a></li>
</ul>

<ul class="nav pull-right">
{{#if current_user}}
<li><a href="/#logout">Logout</a></li>
<li><a href="/#logout">{{t "logout"}}</a></li>
{{else}}
<li><a href="/#login">Login</a></li>
<li><a href="/#login">{{t "login"}}</a></li>
{{/if}}
</ul>

Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/app/views/header.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class App.Views.Header extends Backbone.View

initialize: ->
@listenTo App.currentUser, "change:loggedIn", @render
@listenTo App.Vent, "language:change", @render

render: ->
@$el.html(@template({ current_user: App.currentUser.get('loggedIn') }))
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
//= require jquery
//= require ./lib/csrf_hack
//= require handlebars.runtime
//= require i18n
//= require i18n/translations
//= require ./lib/underscore
//= require ./lib/backbone
//= require ./lib/backbone_leave
Expand Down
5 changes: 5 additions & 0 deletions app/views/application/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<%= javascript_tag do %>
<% if Rails.env.development? %>
I18n.translations = <%= I18n.backend.send(:translations).to_json.html_safe %>
<% end %>
<% if current_user %>
var current_user = {
id: <%= current_user.id %>,
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Buggy</title>
<title><%= t ("brand") %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Application < Rails::Application

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.i18n.default_locale = :ru
end
end
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@

# Debug mode disables concatenation and preprocessing of assets.
config.assets.debug = true
config.assets.initialize_on_precompile = true
end
26 changes: 4 additions & 22 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
brand: "Buggy"
projects: "Projects"
login: "Login"
logout: "Logout"
5 changes: 5 additions & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ru:
brand: "Багги"
projects: "Проекты"
login: "Вход"
logout: "Выход"
2 changes: 2 additions & 0 deletions public/javascripts/translations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41c81a1

Please sign in to comment.