Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (28 commits)
  Fix translation of plural HTML keys glebm#193
  Default config: exclude app/assets/videos glebm#194
  fix template config
  Bump to 0.9.5
  Pattern mapper documentation glebm#191
  Pattern mapper implementation glebm#191
  Add missing keys with `nil` value glebm#170
  Avoid changing the locale after running i18n-tasks
  changelog: 187 still not fixed
  Bump to 0.9.4
  Reference resolution reporting
  Document used_keys include_raw_references param
  Remove redundant filtering from unused_keys
  Improve reporting for unused keys
  Possible fix to glebm#187
  Improve reporting for missing ref keys
  minor refactors
  Bump to 0.9.3
  Readme: reference keys
  Copy reference keys as is in add/translate-missing
  ...
  • Loading branch information
bartimaeus committed Apr 26, 2016
2 parents 5267ce1 + e8db4a1 commit 9af52e9
Show file tree
Hide file tree
Showing 114 changed files with 736 additions and 220 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ env:
global:
- TRAVIS=1 COVERAGE=1
# google translate api key:
- secure: Clln+r2rG6adnmVjS0zGMVHs1hOq58UPIqRE73xW3MPLOdozGUyIZ0RrAU2new1h4sqk/5HVwG5NSW7AsUJDGgkNCDx4saJbf/G+oKIity1zNxlHZu5ijZOZGyxYNzGGM4cb2OO6RS6lfzA6TFv2TQtw8DDfKjzG2gpuJOje8sU=
- secure: "LSP0PfgTfRfyjm3iV770tgqF+G1G4lD+s7LSFE7QwsX+HoZPm8SwHW9S0sOThub+qAkOkfPvApvHwL8nBBFPPM+ZZcgBUViLfErUSOKHFLQt6/pMQvpRg+47hSUszedGnxHck6z9q71a/4GrxHcuY+VslCpT+PhCTt0rsAf3bvY="
# codeclimate repo token:
- secure: Qz5xzCujPHN5jGZYiCcsZ73BN5DzJTQwDMuj0kJ+W2nBzGQuQDvADT0rHFsHOhdQ/epZe89pVL8wEbr5GaCZ+iZCt1JfasZpvyvCtwMUkPtjrLxpWwVKlH3u7xqAzyYj7Z8ru0VqHni19d6DPzAaNGyV3gaiI1pR6Y63Ux+msM0=
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 0.9.5

* Add a `PatternMapper` scanner for mapping bits of code to keys [#191](https://github.com/glebm/i18n-tasks/issues/191).
* Add missing keys with `nil` value by passing `--nil-value` to `add-missing`. [#170](https://github.com/glebm/i18n-tasks/issues/170)
* Requiring `i18n-tasks` no longer overrides `I18n.locale`. [#190](https://github.com/glebm/i18n-tasks/issues/190).

## 0.9.4

* Improve reporting for reference keys throughout.

## 0.9.3

* Support i18n `:symbol` reference keys. [#150](https://github.com/glebm/i18n-tasks/issues/150)
* Fixes dynamic key matching issue with nested `#{}`. [#180](https://github.com/glebm/i18n-tasks/issues/180)

## 0.9.2

* Fix ActiveSupport >= 4.0 but < 4.2 compatibility. [#178](https://github.com/glebm/i18n-tasks/issues/178)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gemspec

unless ENV['TRAVIS']
group :development do
gem 'byebug', platforms: [:mri_21, :mri_22, :mswin, :x64_mingw_21, :x64_mingw_22], require: false
gem 'byebug', platforms: [:mri_21, :mri_22, :mri_23, :mswin, :x64_mingw_21, :x64_mingw_22], require: false
gem 'rubinius-debugger', platform: :rbx, require: false
end
end
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
Add i18n-tasks to the Gemfile:

```ruby
gem 'i18n-tasks', '~> 0.9.2'
gem 'i18n-tasks', '~> 0.9.5'
```

Copy the default [configuration file](#configuration):
Expand Down Expand Up @@ -159,6 +159,11 @@ See the full list of tasks with `i18n-tasks --help`.

✔ Plural keys, such as `key.{one,many,other,...}` are fully supported.

#### Reference keys

✔ Reference keys (keys with `:symbol` values) are fully supported. These keys are copied as-is in
`add/translate-missing`, and can be looked up by reference or value in `find`.

#### `t()` keyword arguments

`scope` keyword argument is fully supported by the AST scanner, and also by the Regexp scanner but only when it is the first argument.
Expand Down Expand Up @@ -273,6 +278,12 @@ User.model_name.human
```

You can also explicitly ignore keys appearing in locale files via `ignore*` settings.

If you have helper methods that generate translation keys, such as a `page_title` method that returns `t '.page_title'`,
or a `Spree.t(key)` method that returns `t "spree.#{key}"`, use the built-in `PatternMapper` to map these.

For more complex cases, you can implement a [custom scanner][custom-scanner-docs].

See the [config file][config] to find out more.

<a name="translation-config"></a>
Expand Down Expand Up @@ -327,3 +338,4 @@ Custom tasks can be added easily, see the examples [on the wiki](https://github.
[screenshot-i18n-tasks]: https://i.imgur.com/XZBd8l7.png "i18n-tasks screenshot"
[screenshot-find]: https://i.imgur.com/VxBrSfY.png "i18n-tasks find output screenshot"
[adapter-example]: https://github.com/glebm/i18n-tasks/blob/master/lib/i18n/tasks/data/file_system_base.rb
[custom-scanner-docs]: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ en:
data_format: 'Data format: %{valid_text}.'
key_pattern: Filter by key pattern (e.g. 'common.*')
key_pattern_to_rename: Full key (pattern) to rename. Required
locale: Locale
locale: :i18n_tasks.common.locale
locale_to_translate_from: Locale to translate from
locales_filter: 'Locale(s) to process. Special: base'
missing_types: 'Filter by types: %{valid}'
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# define all the modules to be able to use ::
module I18n
module Tasks
Expand Down
3 changes: 3 additions & 0 deletions lib/i18n/tasks/base_task.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true
require 'i18n/tasks/command_error'
require 'i18n/tasks/split_key'
require 'i18n/tasks/key_pattern_matching'
require 'i18n/tasks/logging'
require 'i18n/tasks/plural_keys'
require 'i18n/tasks/references'
require 'i18n/tasks/html_keys'
require 'i18n/tasks/used_keys'
require 'i18n/tasks/ignore_keys'
Expand All @@ -22,6 +24,7 @@ class BaseTask
include SplitKey
include KeyPatternMatching
include PluralKeys
include References
include HtmlKeys
include UsedKeys
include IgnoreKeys
Expand Down
35 changes: 19 additions & 16 deletions lib/i18n/tasks/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks'
require 'i18n/tasks/commands'
require 'optparse'
Expand All @@ -13,23 +14,25 @@ def initialize
end

def start(argv)
auto_output_coloring do
begin
if run(argv) == :exit_1
exit 1
end
rescue OptionParser::ParseError => e
error e.message, 64
rescue I18n::Tasks::CommandError => e
I18n.with_locale(base_task.internal_locale) do
auto_output_coloring do
begin
error e.message, 78
ensure
log_verbose e.backtrace * "\n"
if run(argv) == :exit_1
exit 1
end
rescue OptionParser::ParseError => e
error e.message, 64
rescue I18n::Tasks::CommandError => e
begin
error e.message, 78
ensure
log_verbose e.backtrace * "\n"
end
rescue Errno::EPIPE
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
# i18n-tasks missing | head
exit 1
end
rescue Errno::EPIPE
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
# i18n-tasks missing | head
exit 1
end
end
rescue ExecutionError => e
Expand All @@ -42,7 +45,7 @@ def run(argv)
end

def context
@context ||= ::I18n::Tasks::Commands.new(base_task).tap(&:set_internal_locale!)
@context ||= ::I18n::Tasks::Commands.new(base_task)
end

def commands
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/collection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/command/dsl'
require 'i18n/tasks/command/options/common'
require 'i18n/tasks/command/options/locales'
Expand Down
5 changes: 1 addition & 4 deletions lib/i18n/tasks/command/commander.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/cli'
require 'i18n/tasks/reports/terminal'
require 'i18n/tasks/reports/spreadsheet'
Expand Down Expand Up @@ -26,10 +27,6 @@ def run(name, opts = {})
end
end

def set_internal_locale!
I18n.locale = i18n.internal_locale
end

protected

def terminal_report
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/commands/data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/commands/eq_base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/commands/health.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/commands/meta.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand Down
9 changes: 6 additions & 3 deletions lib/i18n/tasks/command/commands/missing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/command/collection'

module I18n::Tasks
Expand Down Expand Up @@ -44,21 +45,23 @@ def translate_missing(opt = {})
cmd :add_missing,
pos: '[locale ...]',
desc: t('i18n_tasks.cmd.desc.add_missing'),
args: [:locales, :out_format, arg(:value) + [{default: '%{value_or_default_or_human_key}'}]]
args: [:locales, :out_format, arg(:value) + [{default: '%{value_or_default_or_human_key}'}],
['--nil-value', 'Set value to nil. Takes precedence over the value argument.']]

def add_missing(opt = {})
added = i18n.empty_forest
locales = (opt[:locales] || i18n.locales)
value = opt[:'nil-value'] ? nil : opt[:value]
if locales[0] == i18n.base_locale
# Merge base locale first, as this may affect the value for the other locales
forest = i18n.missing_keys({locales: [locales[0]]}.update(opt.slice(:types, :base_locale))).
set_each_value!(opt[:value])
set_each_value!(value)
i18n.data.merge! forest
added.merge! forest
locales = locales[1..-1]
end
forest = i18n.missing_keys({locales: locales}.update(opt.slice(:types, :base_locale))).
set_each_value!(opt[:value])
set_each_value!(value)
i18n.data.merge! forest
added.merge! forest
log_stderr t('i18n_tasks.add_missing.added', count: added.leaves.count)
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/commands/tree.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/tasks/command/commands/usages.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand All @@ -15,7 +16,7 @@ module Usages

def find(opt = {})
opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first)
print_forest i18n.used_tree(strict: opt[:strict], key_filter: opt[:filter].presence), opt, :used_keys
print_forest i18n.used_tree(strict: opt[:strict], key_filter: opt[:filter].presence, include_raw_references: true), opt, :used_keys
end

cmd :unused,
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/commands/xlsx.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module Commands
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module DSL
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/option_parsers/enum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module OptionParsers
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/option_parsers/locale.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
module Command
module OptionParsers
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/options/common.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/command/dsl'

module I18n::Tasks
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/options/data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/command/option_parsers/enum'

module I18n::Tasks
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command/options/locales.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/command/option_parsers/locale'

module I18n::Tasks
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/command_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n
module Tasks
# When this type of error is caught:
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/commands.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/command/dsl'
require 'i18n/tasks/command/collection'
require 'i18n/tasks/command/commands/health'
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks::Configuration
DEFAULTS = {
base_locale: 'en'.freeze,
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/console_context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module I18n::Tasks
class ConsoleContext < BaseTask
def to_s
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/tasks/data.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/data/file_system'

module I18n::Tasks
Expand All @@ -10,7 +11,7 @@ module Data
# @see I18n::Tasks::Data::FileSystem
def data
@data ||= begin
data_config = (config[:data] || {}).deep_symbolize_keys
data_config = (config[:data] || {}).deep_symbolize_keys
data_config.merge!(base_locale: base_locale, locales: config[:locales])
adapter_class = data_config[:adapter].presence || data_config[:class].presence || DATA_DEFAULTS[:adapter]
adapter_class = adapter_class.to_s
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/adapter/json_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'json'

module I18n::Tasks
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/adapter/yaml_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'yaml'
module I18n::Tasks
module Data
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/file_formats.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'fileutils'

module I18n
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/file_system.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/data/file_system_base'
require 'i18n/tasks/data/adapter/json_adapter'
require 'i18n/tasks/data/adapter/yaml_adapter'
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/file_system_base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/data/tree/node'
require 'i18n/tasks/data/router/pattern_router'
require 'i18n/tasks/data/router/conservative_router'
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/router/conservative_router.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/data/router/pattern_router'

module I18n::Tasks
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/data/router/pattern_router.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'i18n/tasks/key_pattern_matching'
require 'i18n/tasks/data/tree/node'

Expand Down
15 changes: 14 additions & 1 deletion lib/i18n/tasks/data/tree/node.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

require 'i18n/tasks/data/tree/traversal'
require 'i18n/tasks/data/tree/siblings'
Expand Down Expand Up @@ -73,6 +74,10 @@ def data?
@data.present?
end

def reference?
value.is_a?(Symbol)
end

def get(key)
children.get(key)
end
Expand Down Expand Up @@ -154,12 +159,20 @@ def inspect(level = 0)
Term::ANSIColor.dark '∅'
else
[Term::ANSIColor.color(1 + level % 15, key),
(": #{Term::ANSIColor.cyan(value.to_s)}" if leaf?),
(": #{format_value_for_inspect(value)}" if leaf?),
(" #{data}" if data?)].compact.join
end
[' ' * level, label, ("\n" + children.map { |c| c.inspect(level + 1) }.join("\n") if children?)].compact.join
end

def format_value_for_inspect(value)
if value.is_a?(Symbol)
"#{Term::ANSIColor.bold(Term::ANSIColor.yellow '⮕ ')}#{Term::ANSIColor.yellow value.to_s}"
else
Term::ANSIColor.cyan(value.to_s)
end
end

protected

def dirty!
Expand Down
Loading

0 comments on commit 9af52e9

Please sign in to comment.