diff --git a/CHANGES.md b/CHANGES.md index 7d922dbc..5eebd7b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index f010fe10..5f3af21c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' @@ -67,7 +69,6 @@ en: common: base_value: Base Value continue_q: Continue? - details: Details key: Key locale: Locale n_more: "%{count} more" @@ -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: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index e103e3bd..b2ec8bd0 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -68,7 +68,6 @@ ru: common: base_value: "Исходное значение" continue_q: "Продолжить?" - details: "Детали" key: "Ключ" locale: "Язык" n_more: "ещё %{count}" @@ -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: diff --git a/lib/i18n/tasks/missing_keys.rb b/lib/i18n/tasks/missing_keys.rb index 85653929..0312fd40 100644 --- a/lib/i18n/tasks/missing_keys.rb +++ b/lib/i18n/tasks/missing_keys.rb @@ -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 diff --git a/lib/i18n/tasks/reports/terminal.rb b/lib/i18n/tasks/reports/terminal.rb index bfebc6bf..bb288b5c 100644 --- a/lib/i18n/tasks/reports/terminal.rb +++ b/lib/i18n/tasks/reports/terminal.rb @@ -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 @@ -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}" @@ -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 'ø' @@ -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)