1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Add gettext calls for i18n

This commit is contained in:
Daniel Barber 2018-04-08 22:28:21 -04:00
parent 6a72e5f404
commit 1f9b9e02e2
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
9 changed files with 52 additions and 27 deletions

View File

@ -6,6 +6,7 @@ defmodule Chess.Store.Game do
import Ecto.Changeset
import Ecto.Query
import ChessWeb.Gettext
alias Chess.Board
alias Chess.Store.Game
@ -52,7 +53,7 @@ defmodule Chess.Store.Game do
changeset
|> add_error(
:board,
"That move would leave your king in check"
gettext("That move would leave your king in check")
)
else
changeset

View File

@ -1,7 +1,9 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
<p>
<%= gettext "Oops, something went wrong! Please check the errors below." %>
</p>
</div>
<% end %>

View File

@ -1,21 +1,30 @@
<h2>Listing games</h2>
<h2><%= gettext "Listing games" %></h2>
<table class="table">
<tbody>
<%= for game <- @games do %>
<tr class="<%= turn_class(@conn, game) %>">
<td>
<span class="player-indicator"><img src="images/pawn_<%= player_colour(@conn, game) %>.svg"></span>
<%= link "Game with #{opponent(@conn, game).name}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %>
<span class="player-indicator">
<img src="images/pawn_<%= player_colour(@conn, game) %>.svg">
</span>
<%= link gettext("Game with %{name}",
name: opponent(@conn, game).name),
to: game_path(@conn, :show, game),
class: "btn btn-default btn-xs" %>
</td>
<td>
<%= if your_turn?(@conn, game) do %>Your turn<% end %>
<%= if your_turn?(@conn, game), do: gettext("Your turn") %>
</td>
<td>
Started on <%= Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime) %>
</td>
<td class="text-right">
<%= link "Delete", to: game_path(@conn, :delete, game), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>
<%= link gettext("Delete"),
to: game_path(@conn, :delete, game),
method: :delete,
data: [confirm: gettext("Are you sure?")],
class: "btn btn-danger btn-xs" %>
</td>
</tr>
<% end %>
@ -23,5 +32,5 @@
</table>
<p>
<%= link "New game", to: game_path(@conn, :new), class: "button" %>
<%= link gettext("New game"), to: game_path(@conn, :new), class: "button" %>
</p>

View File

@ -1,14 +1,17 @@
<h2>New game</h2>
<h2><%= gettext "New game" %></h2>
<%= form_for @changeset, game_path(@conn, :create), [class: "create-game"],
fn form -> %>
<div class="form-group">
<%= label form, :opponent_id %>
<%= select form, :opponent_id, @opponents, prompt: "Choose an opponent" %>
<%= select form,
:opponent_id,
@opponents,
prompt: gettext("Choose an opponent") %>
<%= error_tag form, :opponent_id %>
</div>
<div class="form-group">
<%= submit "Create game", class: "button" %>
<%= submit gettext("Create game"), class: "button" %>
</div>
<% end %>

View File

@ -1,4 +1,4 @@
<p><%= link "Back to games", to: game_path(@conn, :index) %></p>
<p><%= link gettext("Back to games"), to: game_path(@conn, :index) %></p>
<h2>Game with <%= opponent(@conn, @game).name %></h2>

View File

@ -7,32 +7,38 @@
<meta name="description" content="">
<meta name="author" content="">
<title>Shall We Play a Game?</title>
<title><%= gettext "Shall We Play a Game?" %></title>
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
</head>
<body>
<header role="banner">
<div class="container">
<h1>Chess</h1>
<h1><%= gettext "Chess" %></h1>
<nav class="user-nav" role="user">
<%= if current_user(@conn) do %>
<%= current_user(@conn).name %> (<%= current_user(@conn).email %>)
|
<%= link("Log out", to: session_path(@conn, :delete), method: :delete) %>
<%= link gettext("Log out"),
to: session_path(@conn, :delete),
method: :delete %>
<% else %>
<%= link("Register", to: registration_path(@conn, :new)) %>
<%= link gettext("Register"), to: registration_path(@conn, :new) %>
|
<%= link("Log in", to: session_path(@conn, :new)) %>
<%= link gettext("Log in"), to: session_path(@conn, :new) %>
<% end %>
</nav>
</div>
</header>
<div class="container alerts">
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<p class="alert alert-info" role="alert">
<%= get_flash(@conn, :info) %>
</p>
<p class="alert alert-danger" role="alert">
<%= get_flash(@conn, :error) %>
</p>
</div>
<main role="main">

View File

@ -1,9 +1,11 @@
<h2>Register</h2>
<h2><%= gettext "Register" %></h2>
<%= form_for @changeset, registration_path(@conn, :create), [class: "create-registration"], fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
<p>
<%= gettext "Oops, something went wrong! Please check the errors below." %>
</p>
</div>
<% end %>
@ -19,6 +21,6 @@
</div>
</div>
<div class="form-group">
<%= submit "Register", class: "btn btn-primary" %>
<%= submit gettext("Register"), class: "btn btn-primary" %>
</div>
<% end %>

View File

@ -1,9 +1,11 @@
<h2>Log in</h2>
<h2><%= gettext "Log in" %></h2>
<%= form_for @changeset, session_path(@conn, :create), [class: "create-session"], fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
<p>
<%= gettext "Oops, something went wrong! Please check the errors below." %>
</p>
</div>
<% end %>
@ -16,6 +18,6 @@
</div>
</div>
<div class="form-group">
<%= submit "Log in", class: "btn btn-primary" %>
<%= submit gettext("Log in"), class: "btn btn-primary" %>
</div>
<% end %>

View File

@ -2,11 +2,11 @@ defmodule ChessWeb.ErrorView do
use ChessWeb, :view
def render("404.html", _assigns) do
"Page not found"
gettext "Page not found"
end
def render("500.html", _assigns) do
"Internal server error"
gettext "Internal server error"
end
# In case no render clause matches or no