add traductions

This commit is contained in:
2021-04-24 23:46:16 +02:00
parent f43ba76984
commit 9082e5255e
62 changed files with 413 additions and 38 deletions

View File

@@ -2,11 +2,25 @@ class ApplicationController < ActionController::Base
around_action :switch_locale around_action :switch_locale
def switch_locale(&action) def switch_locale(&action)
locale = I18n.locale_available?(request.headers['Locale']) ? request.headers['Locale'] : I18n.default_locale locale = extract_locale
I18n.with_locale(locale, &action) I18n.with_locale(locale, &action)
end end
def new_session_path(_scope) def new_session_path(_scope)
new_user_session_path new_user_session_path
end end
def extract_locale
if params[:locale]
I18n.locale_available?(params[:locale]) ? params[:locale] : I18n.default_locale
elsif request.env['HTTP_ACCEPT_LANGUAGE']
I18n.locale_available?(request.env['HTTP_ACCEPT_LANGUAGE']) ? request.env['HTTP_ACCEPT_LANGUAGE'] : I18n.default_locale
else
I18n.default_locale
end
end
def default_url_options
{ locale: I18n.locale }
end
end end

View File

@@ -12,6 +12,7 @@ import "bootstrap"
import "../stylesheets/application" import "../stylesheets/application"
import "@fortawesome/fontawesome-free/css/all" import "@fortawesome/fontawesome-free/css/all"
import "flag-icon-css/sass/flag-icon"
document.addEventListener("turbolinks:load", () => { document.addEventListener("turbolinks:load", () => {
$('[data-toggle="tooltip"]').tooltip() $('[data-toggle="tooltip"]').tooltip()

View File

@@ -0,0 +1,19 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fas fa-globe-europe"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-de"></span>'.html_safe, root_path(locale: 'de-de') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-gb"></span>'.html_safe, root_path(locale: 'en-gb') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-us"></span>'.html_safe, root_path(locale: 'en-us') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-mx"></span>'.html_safe, root_path(locale: 'es-mx') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-br"></span>'.html_safe, root_path(locale: 'pt-br') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-es"></span>'.html_safe, root_path(locale: 'es-es') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-fr"></span>'.html_safe, root_path(locale: 'fr-fr') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-it"></span>'.html_safe, root_path(locale: 'it') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-ru"></span>'.html_safe, root_path(locale: 'ru-ru') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-kr"></span>'.html_safe, root_path(locale: 'ko') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-tw"></span>'.html_safe, root_path(locale: 'zh-tw') %></li>
<li class="dropdown-item"><%= link_to '<span class="flag-icon flag-icon-cn"></span>'.html_safe, root_path(locale: 'zh-cn') %></li>
</ul>
</li>

View File

@@ -5,16 +5,19 @@
<% if user_signed_in? %> <% if user_signed_in? %>
<ul class="navbar-nav mb-2 mb-lg-0"> <ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" aria-current="page" href="<%= wow_characters_path %>">Characters</a> <a class="nav-link active" aria-current="page" href="<%= wow_characters_path %>"><%= t('layouts.navbar.characters') %></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" aria-current="page" href="<%= wow_mounts_path %>">Mounts</a> <a class="nav-link active" aria-current="page" href="<%= wow_mounts_path %>"><%= t('layouts.navbar.mounts') %></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" aria-current="page" href="<%= wow_pets_path %>">Pets</a> <a class="nav-link active" aria-current="page" href="<%= wow_pets_path %>"><%= t('layouts.navbar.pets') %></a>
</li> </li>
</ul> </ul>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0"> <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<%= render 'layouts/locales' %>
</ul>
<ul class="navbar-nav mb-2 mb-lg-0">
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Menu Menu
@@ -26,7 +29,10 @@
</ul> </ul>
</li> </li>
<% else %> <% else %>
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<%= render 'layouts/locales' %>
<%= link_to 'Sign in with <i class="fab fa-battle-net"></i>'.html_safe, user_bnet_omniauth_authorize_path, method: :post, class: "btn btn-primary nav-item" %> <%= link_to 'Sign in with <i class="fab fa-battle-net"></i>'.html_safe, user_bnet_omniauth_authorize_path, method: :post, class: "btn btn-primary nav-item" %>
</ul>
<% end %> <% end %>
</ul> </ul>
</div> </div>

View File

@@ -4,13 +4,13 @@
<thead> <thead>
<tr> <tr>
<th scope="col"></th> <th scope="col"></th>
<th scope="col"><%= t('character_list.name') %></th> <th scope="col"><%= t('wow_characters.character_list.name') %></th>
<th scope="col"><%= t('character_list.gender') %></th> <th scope="col"><%= t('wow_characters.character_list.gender') %></th>
<th scope="col"><%= t('character_list.realm') %></th> <th scope="col"><%= t('wow_characters.character_list.realm') %></th>
<th scope="col"><%= t('character_list.race') %></th> <th scope="col"><%= t('wow_characters.character_list.race') %></th>
<th scope="col"><%= t('character_list.class') %></th> <th scope="col"><%= t('wow_characters.character_list.class') %></th>
<th scope="col"><%= t('character_list.faction') %></th> <th scope="col"><%= t('wow_characters.character_list.faction') %></th>
<th scope="col"><%= t('character_list.level') %></th> <th scope="col"><%= t('wow_characters.character_list.level') %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@@ -3,9 +3,9 @@
<table class="table table-hover table-dark table-image"> <table class="table table-hover table-dark table-image">
<thead> <thead>
<tr> <tr>
<th scope="col"><%= t('mount_list.name') %></th> <th scope="col"><%= t('wow_mounts.mount_list.name') %></th>
<th scope="col"><%= t('mount_list.description') %></th> <th scope="col"><%= t('wow_mounts.mount_list.description') %></th>
<th scope="col"><%= t('mount_list.owned') %></th> <th scope="col"><%= t('wow_mounts.mount_list.owned') %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@@ -3,9 +3,9 @@
<table class="table table-hover table-dark table-image"> <table class="table table-hover table-dark table-image">
<thead> <thead>
<tr> <tr>
<th scope="col"><%= t('pet_list.name') %></th> <th scope="col"><%= t('wow_pets.pet_list.name') %></th>
<th scope="col"><%= t('pet_list.description') %></th> <th scope="col"><%= t('wow_pets.pet_list.description') %></th>
<th scope="col"><%= t('pet_list.owned') %></th> <th scope="col"><%= t('wow_pets.pet_list.owned') %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@@ -24,5 +24,6 @@ module Northwhale2
config.i18n.default_locale = 'en-gb' config.i18n.default_locale = 'en-gb'
config.i18n.available_locales = ['de-de', 'en-gb', 'en-us', 'es-mx', 'pt-br', 'es-es', 'fr-fr', 'it', 'ru-ru', 'ko', 'zh-tw', 'zh-cn'] config.i18n.available_locales = ['de-de', 'en-gb', 'en-us', 'es-mx', 'pt-br', 'es-es', 'fr-fr', 'it', 'ru-ru', 'ko', 'zh-tw', 'zh-cn']
config.i18n.fallbacks.map = { 'fr-fr': :'fr-ch' } config.i18n.fallbacks.map = { 'fr-fr': :'fr-ch' }
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
end end
end end

View File

@@ -30,19 +30,3 @@
# available at https://guides.rubyonrails.org/i18n.html. # available at https://guides.rubyonrails.org/i18n.html.
en-gb: en-gb:
character_list:
name: "Name"
gender: "Gender"
realm: "Realm"
race: "Race"
class: "Class"
faction: "Faction"
level: "Level"
mount_list:
name: "Name"
description: "Description"
owned: "Owned"
pet_list:
name: "Name"
description: "Description"
owned: "Owned"

View File

@@ -0,0 +1,6 @@
de-de:
layouts:
navbar:
characters: "Zeichen"
mounts: "Anschlüsse"
pets: "Maskottchen"

View File

@@ -0,0 +1,6 @@
en-gb:
layouts:
navbar:
characters: "Characters"
mounts: "Mounts"
pets: "Pets"

View File

@@ -0,0 +1,6 @@
en-us:
layouts:
navbar:
characters: "Characters"
mounts: "Mounts"
pets: "Pets"

View File

@@ -0,0 +1,6 @@
es-es:
layouts:
navbar:
characters: "Caracteres"
mounts: "Montajes"
pets: "Mascotas"

View File

@@ -0,0 +1,6 @@
es-mx:
layouts:
navbar:
characters: "Caracteres"
mounts: "Montajes"
pets: "Mascotas"

View File

@@ -0,0 +1,6 @@
fr-fr:
layouts:
navbar:
characters: "Personnages"
mounts: "Montures"
pets: "Mascotte"

View File

@@ -0,0 +1,6 @@
it:
layouts:
navbar:
characters: "Personaggi"
mounts: "Monti"
pets: "Mascotte"

View File

@@ -0,0 +1,6 @@
ko:
layouts:
navbar:
characters: "캐릭터"
mounts: "마운트"
pets: "마스코트"

View File

@@ -0,0 +1,6 @@
pt-br:
layouts:
navbar:
characters: "Personagens"
mounts: "Montagens"
pets: "Mascote"

View File

@@ -0,0 +1,6 @@
ru-ru:
layouts:
navbar:
characters: "Символы"
mounts: "Крепления"
pets: "Талисман"

View File

@@ -0,0 +1,6 @@
zh-cn:
layouts:
navbar:
characters: "人物"
mounts: "坐骑"
pets: "吉祥物"

View File

@@ -0,0 +1,6 @@
zh-tw:
layouts:
navbar:
characters: "人物"
mounts: "坐骑"
pets: "吉祥物"

View File

@@ -0,0 +1,10 @@
de-de:
wow_characters:
character_list:
name: "Name"
gender: "Geschlecht"
realm: "Reich"
race: "Rennen"
class: "Klasse"
faction: "Fraktion"
level: "Niveau"

View File

@@ -0,0 +1,10 @@
en-gb:
wow_characters:
character_list:
name: "Name"
gender: "Gender"
realm: "Realm"
race: "Race"
class: "Class"
faction: "Faction"
level: "Level"

View File

@@ -0,0 +1,10 @@
en-us:
wow_characters:
character_list:
name: "Name"
gender: "Gender"
realm: "Realm"
race: "Race"
class: "Class"
faction: "Faction"
level: "Level"

View File

@@ -0,0 +1,10 @@
es-es:
wow_characters:
character_list:
name: "Nombre"
gender: "Género"
realm: "Reino"
race: "Carrera"
class: "Clase"
faction: "Facción"
level: "Nivel"

View File

@@ -0,0 +1,10 @@
es-mx:
wow_characters:
character_list:
name: "Nombre"
gender: "Género"
realm: "Reino"
race: "Carrera"
class: "Clase"
faction: "Facción"
level: "Nivel"

View File

@@ -0,0 +1,10 @@
fr-fr:
wow_characters:
character_list:
name: "Nom"
gender: "Genre"
realm: "Royaume"
race: "Race"
class: "Classe"
faction: "Faction"
level: "Niveau"

View File

@@ -0,0 +1,10 @@
it:
wow_characters:
character_list:
name: "Nome"
gender: "Genere"
realm: "Regno"
race: "Gara"
class: "Classe"
faction: "Fazione"
level: "Livello"

View File

@@ -0,0 +1,10 @@
ko:
wow_characters:
character_list:
name: "이름"
gender: "성별"
realm: "왕국"
race: "경주"
class: "수업"
faction: "파벌"
level: "수평"

View File

@@ -0,0 +1,10 @@
pt-br:
wow_characters:
character_list:
name: "Nome"
gender: "Gênero"
realm: "Reino"
race: "Corrida"
class: "Classe"
faction: "Facção"
level: "Nível"

View File

@@ -0,0 +1,10 @@
ru-ru:
wow_characters:
character_list:
name: "имя"
gender: "Пол"
realm: "Царство"
race: "раса"
class: "Учебный класс"
faction: "Фракция"
level: "Уровень"

View File

@@ -0,0 +1,10 @@
zh-cn:
wow_characters:
character_list:
name: "名称"
gender: "性别"
realm: "领域"
race: "种族"
class: "类"
faction: "派"
level: "水平"

View File

@@ -0,0 +1,10 @@
zh-tw:
wow_characters:
character_list:
name: "名称"
gender: "性别"
realm: "领域"
race: "种族"
class: "类"
faction: "派"
level: "水平"

View File

@@ -0,0 +1,6 @@
de-de:
wow_mounts:
mount_list:
name: "Name"
description: "Beschreibung"
owned: "Eigentum"

View File

@@ -0,0 +1,6 @@
en-gb:
wow_mounts:
mount_list:
name: "Name"
description: "Description"
owned: "Owned"

View File

@@ -0,0 +1,6 @@
en-us:
wow_mounts:
mount_list:
name: "Name"
description: "Description"
owned: "Owned"

View File

@@ -0,0 +1,6 @@
es-es:
wow_mounts:
mount_list:
name: "Nombre"
description: "Descripción"
owned: "Propiedad"

View File

@@ -0,0 +1,6 @@
es-mx:
wow_mounts:
mount_list:
name: "Nombre"
description: "Descripción"
owned: "Propiedad"

View File

@@ -0,0 +1,6 @@
en-gb:
wow_mounts:
mount_list:
name: "Nom"
description: "Description"
owned: "Obtenu"

View File

@@ -0,0 +1,6 @@
it:
wow_mounts:
mount_list:
name: "Nome"
description: "Descrizione"
owned: "Di proprietà"

View File

@@ -0,0 +1,6 @@
ko:
wow_mounts:
mount_list:
name: "이름"
description: "기술"
owned: "소유"

View File

@@ -0,0 +1,6 @@
pt-br:
wow_mounts:
mount_list:
name: "Sobrenome"
description: "Descrição"
owned: "Obteve"

View File

@@ -0,0 +1,6 @@
ru-ru:
wow_mounts:
mount_list:
name: "Фамилия"
description: "Описание"
owned: "Получил"

View File

@@ -0,0 +1,6 @@
zh-cn:
wow_mounts:
mount_list:
name: "姓"
description: "描述"
owned: "得到了"

View File

@@ -0,0 +1,6 @@
zh-tw:
wow_mounts:
mount_list:
name: "姓"
description: "描述"
owned: "得到了"

View File

@@ -0,0 +1,6 @@
de-de:
wow_pets:
pet_list:
name: "Name"
description: "Beschreibung"
owned: "Eigentum"

View File

@@ -0,0 +1,6 @@
en-gb:
wow_pets:
pet_list:
name: "Name"
description: "Description"
owned: "Owned"

View File

@@ -0,0 +1,6 @@
en-us:
wow_pets:
pet_list:
name: "Name"
description: "Description"
owned: "Owned"

View File

@@ -0,0 +1,6 @@
es-es:
wow_pets:
pet_list:
name: "Nombre"
description: "Descripción"
owned: "Propiedad"

View File

@@ -0,0 +1,6 @@
es-mx:
wow_pets:
pet_list:
name: "Nombre"
description: "Descripción"
owned: "Propiedad"

View File

@@ -0,0 +1,6 @@
en-gb:
wow_pets:
pet_list:
name: "Nom"
description: "Description"
owned: "Obtenu"

View File

@@ -0,0 +1,6 @@
it:
wow_pets:
pet_list:
name: "Nome"
description: "Descrizione"
owned: "Di proprietà"

View File

@@ -0,0 +1,6 @@
ko:
wow_pets:
pet_list:
name: "이름"
description: "기술"
owned: "소유"

View File

@@ -0,0 +1,6 @@
pt-br:
wow_pets:
pet_list:
name: "Sobrenome"
description: "Descrição"
owned: "Obteve"

View File

@@ -0,0 +1,6 @@
ru-ru:
wow_pets:
pet_list:
name: "Фамилия"
description: "Описание"
owned: "Получил"

View File

@@ -0,0 +1,6 @@
zh-cn:
wow_pets:
pet_list:
name: "姓"
description: "描述"
owned: "得到了"

View File

@@ -0,0 +1,6 @@
zh-tw:
wow_pets:
pet_list:
name: "姓"
description: "描述"
owned: "得到了"

View File

@@ -9,7 +9,9 @@ Rails.application.routes.draw do
end end
root to: "home#index" root to: "home#index"
mount Sidekiq::Web => '/sidekiq' mount Sidekiq::Web => '/sidekiq'
scope "/:locale" do
resources :wow_characters, only: [:index, :show] resources :wow_characters, only: [:index, :show]
resources :wow_mounts, only: [:index, :show] resources :wow_mounts, only: [:index, :show]
resources :wow_pets, only: [:index, :show] resources :wow_pets, only: [:index, :show]
end end
end

View File

@@ -0,0 +1,5 @@
class AddLocaleToUser < ActiveRecord::Migration[6.1]
def change
add_column :users, :locale, :string, default: 'en-gb'
end
end

3
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_04_23_153941) do ActiveRecord::Schema.define(version: 2021_04_24_192800) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -79,6 +79,7 @@ ActiveRecord::Schema.define(version: 2021_04_23_153941) do
t.string "token" t.string "token"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.string "locale", default: "en-gb"
t.index ["battletag"], name: "index_users_on_battletag", unique: true t.index ["battletag"], name: "index_users_on_battletag", unique: true
end end

View File

@@ -9,6 +9,7 @@
"@rails/ujs": "^6.0.0", "@rails/ujs": "^6.0.0",
"@rails/webpacker": "5.2.1", "@rails/webpacker": "5.2.1",
"bootstrap": "^5.0.0-beta3", "bootstrap": "^5.0.0-beta3",
"flag-icon-css": "^3.5.0",
"jquery": "^3.6.0", "jquery": "^3.6.0",
"turbolinks": "^5.2.0" "turbolinks": "^5.2.0"
}, },

5
yarn.lock generated
View File

@@ -3066,6 +3066,11 @@ findup-sync@^3.0.0:
micromatch "^3.0.4" micromatch "^3.0.4"
resolve-dir "^1.0.1" resolve-dir "^1.0.1"
flag-icon-css@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/flag-icon-css/-/flag-icon-css-3.5.0.tgz#430747d5cb91e60babf85494de99173c16dc7cf2"
integrity sha512-pgJnJLrtb0tcDgU1fzGaQXmR8h++nXvILJ+r5SmOXaaL/2pocunQo2a8TAXhjQnBpRLPtZ1KCz/TYpqeNuE2ew==
flatted@^3.0.4: flatted@^3.0.4:
version "3.1.1" version "3.1.1"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469"