Skip to content

Commit

Permalink
more locale checks
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Nov 16, 2012
1 parent bc68c4b commit 4c927b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
43 changes: 38 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,21 @@ namespace :locale do
task :check do
require File.join(File.dirname(__FILE__), 'lib/olelo/virtualfs')
require 'yaml'
files = {}
require 'set'

locales = {}
Dir['**/*.rb'].each do |file|
begin
files[file] = Olelo::VirtualFS::Embedded.new(file).read('locale.yml')
locales[file] = YAML.load(Olelo::VirtualFS::Embedded.new(file).read('locale.yml'))
rescue
end
end
Dir['**/locale.yml'].each do |file|
files[file] = File.read(file)
locales[file] = YAML.load_file(file)
end

files.each do |file, content|
locales.each do |file, translations|
puts "Checking #{file}"
translations = YAML.load(content)
en = translations['en']
raise 'en locale missing' unless en
en_keys = en.keys
Expand All @@ -130,6 +131,38 @@ namespace :locale do
end
end
end

locale_defined = {}
locales.each do |file,translations|
translations.each do |locale, hash|
hash.keys.each do |key|
(locale_defined[key] ||= Set.new) << file
end
end
end

locale_used = {}
Dir['**/*.rb', '**/*.slim'].each do |file|
File.read(file).scan(/:(\w+)\.t[^\w]/) do
(locale_used[$1] ||= Set.new) << file
end
end

locale_defined.each do |key,files|
unless locale_used[key]
puts "#{key} defined in #{files.to_a.join(', ')} is unused"
end
end

locale_used.each do |key, files|
unless locale_defined[key]
puts "#{key} used in #{files.to_a.join(', ')} is undefined"
end
end

(locale_defined.keys + locale_used.keys).sort.uniq.each do |key|
puts "#{key} - defined in #{locale_defined[key].to_a.join(', ')} - used in #{locale_used[key].to_a.join(', ')}"
end
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/olelo/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def add(locale)
# @return [String] translated string
#
def translate(key, args = {})
if !key.to_s.ends_with?('_plural') && args[:count] && args[:count] != 1
translate("#{key}_plural", args)
elsif @translations[key]
if @translations[key]
@translations[key] % args
else
args[:fallback] || "##{key}"
Expand Down
20 changes: 0 additions & 20 deletions lib/olelo/locale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ cs_CZ:
comment: 'Komentář'
confirm_password: 'Potvrdit heslo'
create_page: 'Vytvořit stránku %{page}'
create_redirect: 'Vytvořit přesměrování'
delete: 'Smazat'
delete_page: 'Smazat stránku %{page}'
deleted: 'Smazáno'
Expand All @@ -28,7 +27,6 @@ cs_CZ:
error_occurred: 'Ouvej! Vyskytla se chyba.'
file: 'Soubor'
groups: 'Skupiny'
head: 'Nejnovější'
history: 'Historie'
info_binary: 'Stránka %{page} je binární typ %{type} a nemůže být editována jako textový soubor.'
invalid_email: 'e-mail je neplatný'
Expand All @@ -50,7 +48,6 @@ cs_CZ:
no_changes: 'Žádné změny'
not_found_text: 'Pardon, stránka, kterou hledáte, nebyla nalezena.'
old_password: 'Staré heslo'
page: 'Stránka'
page_deleted: 'Stránka %{page} smazána.'
page_edited: 'Stránka %{page} editována'#
not_found_title: '404 Not found'
Expand All @@ -71,9 +68,7 @@ cs_CZ:
settings: 'Nastavení'
signup: 'Registrovat se'
summary: 'Souhrn'
text: 'Text'
title: 'Titulek'
tree: 'Strom'
type_select: 'Vybrat hodnotu'
type_stringlist: 'Řetězce oddělené čárkou'
upload: 'Nahrát'
Expand Down Expand Up @@ -101,7 +96,6 @@ de:
comment: 'Kommentar'
confirm_password: 'Bestätige Passwort'
create_page: 'Neue %{page}'
create_redirect: 'Weiterleitung'
delete: 'Löschen'
delete_page: 'Lösche %{page}'
deleted: 'Gelöscht'
Expand All @@ -115,7 +109,6 @@ de:
error_occurred: 'Hoppla! Es ist ein Fehler aufgetreten.'
file: 'Datei'
groups: 'Gruppen'
head: 'Kopf'
history: 'Historie'
info_binary: '%{page} ist eine Datei mit dem Typ %{type} und kann nicht wie eine Textdatei bearbeitet werden.'
invalid_email: 'E-Mail ist ungültig'
Expand All @@ -138,7 +131,6 @@ de:
not_found_text: 'Die Seite wurde leider nicht gefunden.'
not_found_title: '404 Nicht gefunden'
old_password: 'Altes Passwort'
page: 'Seite'
page_deleted: '%{page} gelöscht.'
page_edited: '%{page} bearbeitet'
page_moved: '%{page} verschoben nach %{destination}.'
Expand All @@ -158,9 +150,7 @@ de:
settings: 'Einstellungen'
signup: 'Konto anlegen'
summary: 'Zusammenfassung'
text: 'Text'
title: 'Titel'
tree: 'Baum'
type_select: 'Wert auswählen'
type_stringlist: 'Durch Komma getrennte Strings'
upload: 'Hochladen'
Expand Down Expand Up @@ -188,7 +178,6 @@ en:
comment: 'Comment'
confirm_password: 'Confirm password'
create_page: 'Create %{page}'
create_redirect: 'Create redirect'
delete: 'Delete'
delete_page: 'Delete %{page}'
deleted: 'Deleted'
Expand All @@ -202,7 +191,6 @@ en:
error_occurred: 'Oh snap! An error occurred.'
file: 'File'
groups: 'Groups'
head: 'Head'
history: 'History'
info_binary: '%{page} is a binary %{type} and cannot be edited like a text file.'
invalid_email: 'E-Mail is invalid'
Expand All @@ -221,7 +209,6 @@ en:
not_found_text: 'Sorry, the page you were looking for was not found.'
not_found_title: '404 Not found'
old_password: 'Old password'
page: 'Page'
page_deleted: '%{page} deleted.'
page_edited: '%{page} edited'
page_moved: '%{page} moved to %{destination}.'
Expand All @@ -241,9 +228,7 @@ en:
settings: 'Settings'
signup: 'Sign up'
summary: 'Summary'
text: 'Text'
title: 'Title'
tree: 'Tree'
type_select: 'Select value'
type_stringlist: 'Comma-separated strings'
upload: 'Upload'
Expand Down Expand Up @@ -271,7 +256,6 @@ fr:
comment: "Commentaire"
confirm_password: "Confirmer le mot de passe"
create_page: "Créer %{page}"
create_redirect: "Créer une redirection"
delete: "Effacer"
delete_page: "Effacer %{page}"
deleted: "Supprimé"
Expand All @@ -285,7 +269,6 @@ fr:
error_occurred: "Oops ! Une erreur est survenue."
file: "Fichier"
groups: "Groupes"
head: "Tête"
history: "Historique"
info_binary: "%{page} est un binaire %{type} et ne peut pas être édité comme un fichier texte."
invalid_email: "Courriel invalide"
Expand All @@ -304,7 +287,6 @@ fr:
not_found_text: "Désolé, la page que vous recherchez n'a pas été trouvée."
not_found_title: '404 Non trouvé'
old_password: "Ancien mot de passe"
page: "Page"
page_deleted: "%{page} supprimé."
page_edited: "%{page} éditée"
page_moved: "%{page} déplacer vers %{destination}."
Expand All @@ -324,9 +306,7 @@ fr:
settings: "Paramètres"
signup: "S'enregistrer"
summary: "Sommaire"
text: "Texte"
title: "Titre"
tree: "Arbre"
type_select: "Sélectionnez une valeur"
type_stringlist: "Chaînes séparées par des virgules"
upload: "Téléverser"
Expand Down
3 changes: 2 additions & 1 deletion plugins/repositories/git_grep.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
description 'Searching via git-grep'

class ::Olelo::Application
Expand Down Expand Up @@ -60,7 +61,7 @@ def emphasize(s)
@@ git_grep.slim
- title :search_results.t(pattern: params[:pattern])
h1= title
p= :match.t(count: @matches.length)
p= @matches.length == 1 ? :match.t : :match_plural.t(count: @matches.length)
.search
- @matches.each do |path, content|
.match
Expand Down

0 comments on commit 4c927b8

Please sign in to comment.