Skip to content

Commit

Permalink
Improve missing key info column
Browse files Browse the repository at this point in the history
* Change title from "Details" to "Value in other locales or source" #130
* Show the other locale name
  • Loading branch information
glebm committed Mar 7, 2015
1 parent 8d3cc44 commit d0e7ff2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Fix relative keys when controller name consists of more than one word by [Yuji Nakayama](https://github.com/yujinakayama) [#132](https://github.com/glebm/i18n-tasks/pull/132).
* Support keys with UTF8 word characters in the name. [#133](https://github.com/glebm/i18n-tasks/issues/133).
* Change missing report column title from "Details" to "Value in other locales or source", display the locale [#130](https://github.com/glebm/i18n-tasks/issues/130).

## 0.7.12

Expand Down
6 changes: 4 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
en:
i18n_tasks:
add_missing:
added: Added %{count} keys
added:
one: Added %{count} key
other: Added %{count} keys
cmd:
args:
default_all: 'Default: all'
Expand Down Expand Up @@ -67,7 +69,6 @@ en:
common:
base_value: Base Value
continue_q: Continue?
details: Details
key: Key
locale: Locale
n_more: "%{count} more"
Expand All @@ -88,6 +89,7 @@ en:
health:
no_keys_detected: No keys detected. Check data.read in config/i18n-tasks.yml.
missing:
details_title: Value in other locales or source
none: No translations are missing.
remove_unused:
confirm:
Expand Down
6 changes: 3 additions & 3 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ ru:
common:
base_value: "Исходное значение"
continue_q: "Продолжить?"
details: "Детали"
key: "Ключ"
locale: "Язык"
n_more: "ещё %{count}"
Expand All @@ -82,13 +81,14 @@ ru:
title: "Данные (%{locales}):"
google_translate:
errors:
no_api_key: Задайте ключ API Google через переменную окружения GOOGLE_TRANSLATE_API_KEY
или translation.api_key в config/i18n-tasks.yml. Получите ключ через https://code.google.com/apis/console.
no_api_key: "Задайте ключ API Google через переменную окружения GOOGLE_TRANSLATE_API_KEY или
translation.api_key в config/i18n-tasks.yml. Получите ключ через https://code.google.com/apis/console."
no_results: Google Translate не дал результатов. Убедитесь в том, что платежная информация
добавлена в https://code.google.com/apis/console.
health:
no_keys_detected: "Ключи не обнаружены. Проверьте data.read в config/i18n-tasks.yml."
missing:
details_title: "На других языках или в коде"
none: "Всё переведено."
remove_unused:
confirm:
Expand Down
6 changes: 4 additions & 2 deletions lib/i18n/tasks/missing_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ def missing_diff_tree(locale, compared_to = base_locale)
data[compared_to].select_keys { |key, _node|
locale_key_missing? locale, depluralize_key(key, compared_to)
}.set_root_key!(locale, type: :missing_diff).keys { |_key, node|
# change path and locale to base
data = {locale: locale, missing_diff_locale: node.data[:locale]}
if node.data.key?(:path)
# change path and locale to base
node.data.update path: LocalePathname.replace_locale(node.data[:path], node.data[:locale], locale), locale: locale
data[:path] = LocalePathname.replace_locale(node.data[:path], node.data[:locale], locale)
end
node.data.update data
}
end

Expand Down
34 changes: 19 additions & 15 deletions lib/i18n/tasks/reports/terminal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def missing_keys(forest = task.missing_keys)
forest = task.collapse_plural_nodes!(forest)
if forest.present?
print_title missing_title(forest)
print_table headings: [cyan(bold(I18n.t('i18n_tasks.common.locale'))), cyan(bold I18n.t('i18n_tasks.common.key')), I18n.t('i18n_tasks.common.details')] do |t|
print_table headings: [cyan(bold(I18n.t('i18n_tasks.common.locale'))),
cyan(bold I18n.t('i18n_tasks.common.key')),
I18n.t('i18n_tasks.missing.details_title')] do |t|
t.rows = sort_by_attr!(forest_to_attr(forest)).map do |a|
[{value: cyan(a[:locale]), alignment: :center}, cyan(a[:key]), key_info(a)]
[{value: cyan(a[:locale]), alignment: :center}, cyan(a[:key]), missing_key_info(a)]
end
end
else
Expand Down Expand Up @@ -74,6 +76,14 @@ def forest_stats(forest, stats = task.forest_stats(forest))

private

def missing_key_info(leaf)
if leaf[:type] == :missing_used
first_occurrence leaf
else
"#{cyan leaf[:data][:missing_diff_locale]} #{leaf[:value].to_s.strip}"
end
end

def print_occurrences(node, full_key = node.full_key)
occurrences = node.data[:source_occurrences]
puts "#{bold "#{full_key}"} #{green(occurrences.size.to_s) if occurrences.size > 1}"
Expand All @@ -84,8 +94,12 @@ def print_occurrences(node, full_key = node.full_key)

def print_locale_key_value_table(locale_key_values)
if locale_key_values.present?
print_table headings: [bold(cyan(I18n.t('i18n_tasks.common.locale'))), bold(cyan(I18n.t('i18n_tasks.common.key'))), I18n.t('i18n_tasks.common.value')] do |t|
t.rows = locale_key_values.map { |(locale, k, v)| [{value: cyan(locale), alignment: :center}, cyan(k), v.to_s] }
print_table headings: [bold(cyan(I18n.t('i18n_tasks.common.locale'))),
bold(cyan(I18n.t('i18n_tasks.common.key'))),
I18n.t('i18n_tasks.common.value')] do |t|
t.rows = locale_key_values.map { |(locale, k, v)|
[{value: cyan(locale), alignment: :center}, cyan(k), v.to_s]
}
end
else
puts 'ø'
Expand Down Expand Up @@ -124,17 +138,7 @@ def key_occurrence(full_key, info)
end

def highlight_key(full_key, line, range = (0..-1))
result = line.dup
result[range] = result[range].sub(full_key) { |m| underline m }
result
end

def key_info(leaf)
if leaf[:type] == :missing_used
first_occurrence leaf
else
leaf[:value].to_s.strip
end
line.dup.tap { |s| s[range] = s[range].sub(full_key) { |m| underline m } }
end

def first_occurrence(leaf)
Expand Down

0 comments on commit d0e7ff2

Please sign in to comment.