Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (58 commits)
  Bump to 0.8.3
  ActiveSupport < 4 compat
  Bump to 0.8.2
  Fix failure on nil values in the data config glebm#142
  Bump to 0.8.1
  bump to 0.8.0
  Update the default config file, edit the Readme
  Config  appends to and not overrides the list glebm#137
  Update CHANGES.md
  Don't require spec_helper where you don't need to.
  Add missing keys detected in source to all locales glebm#134
  cli
  cli.rb: extract help_option
  Verbose option help
  improve CLI DSL
  update template defaults to match
  cli.rb codeclimate
  minor fixes
  test-infra
  slop -> optparse
  ...
  • Loading branch information
bartimaeus committed Apr 30, 2015
2 parents d7b7cc0 + dabcf76 commit 22ea682
Show file tree
Hide file tree
Showing 70 changed files with 1,139 additions and 980 deletions.
2 changes: 0 additions & 2 deletions .jrubyrc

This file was deleted.

9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: ruby
rvm:
- 2.1.3
- 2.0.0
- 2.2.1
- 1.9.3
- jruby
- rbx-2.2.10
- rbx
# travis uses old bundler (https://travis-ci.org/glebm/i18n-tasks/jobs/53485782)
before_install: gem install bundler
cache: bundler
script: bundle exec rspec
env:
global:
- TRAVIS=1
Expand Down
51 changes: 51 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
## 0.8.3

* Fix regression: ActiveSupport < 4 support [#143](https://github.com/glebm/i18n-tasks/issues/143).

## 0.8.2

* Fix failure on nil values in the data config [#142](https://github.com/glebm/i18n-tasks/issues/142).

## 0.8.1

* The default config file now excludes `app/assets/images` and `app/assets/fonts`. Add `*.otf` to ignored extensions.
* If an error message occurs when scanning, the error message now includes the filename [#141](https://github.com/glebm/i18n-tasks/issues/141).

## 0.8.0

* Parse command line arguments with `optparse`. Remove dependency on Slop.
Simplified commands DSL: options are mostly passed directly to optparse.
* `search.relative_roots` default changed from from `%w(app/views)` to
`%w(app/views app/controllers app/helpers app/presenters)`.
* `add-missing` now adds keys detected in source to all locales (previously just base) [#134](https://github.com/glebm/i18n-tasks/issues/134).
* The default spec template no long requires `spec_helper` by default [Daniel Levenson](https://github.com/dleve123) [#135](https://github.com/glebm/i18n-tasks/pull/135).
* `search.exclude` now appends to and not overrides the default exclude list. More extensions excluded by default:
*.css, *.sass, *.scss, *.less, *.yml, and *.json. [#137](https://github.com/glebm/i18n-tasks/issues/137).

## 0.7.13

* 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

* Handle relative keys in controllers nested in modules by [Alexander Tipugin](https://github.com/atipugin). [#128](https://github.com/glebm/i18n-tasks/issues/128).
* Only write files that changed [#125](https://github.com/glebm/i18n-tasks/issues/125).
* Allow `[]` in the non-strict scanner pattern [#127](https://github.com/glebm/i18n-tasks/issues/127).

## 0.7.11

* Set slop dependency to 3.5 to ensure Ruby 1.9 compatibility ([#121](https://github.com/glebm/i18n-tasks/pull/121)).
MRI 1.9 EOL is [February 23, 2015](https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/).
We will support 1.9 until rbx and jruby support 2.0.

## 0.7.10

* Support relative keys in controller action with argument

## 0.7.9

* Support relative keys in Rails controller actions by [Jessie A. Young](https://github.com/jessieay). [#46](https://github.com/glebm/i18n-tasks/issues/46).
* Minor fixes

## 0.7.8

* Fix Google Translate issues with non-string keys [#100](https://github.com/glebm/i18n-tasks/pull/100)
Expand Down
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in i18n-tasks.gemspec
gemspec

group :development do
gem 'byebug', platform: :mri_21, require: false
unless ENV['TRAVIS']
group :development do
gem 'byebug', platforms: [:mri_21, :mri_22], require: false
gem 'rubinius-debugger', platform: :rbx, require: false
end
end

gem 'codeclimate-test-reporter', group: :test, require: nil
161 changes: 31 additions & 130 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Thus addressing the two main problems of [i18n gem][i18n-gem] design:

## Installation

i18n-tasks can be used with any project using [i18n][i18n-gem] (default in Rails), or similar, even if it isn't ruby.
i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (default in Rails).

Add it to the Gemfile:
Add i18n-tasks to the Gemfile:

```ruby
gem 'i18n-tasks', '~> 0.7.8'
gem 'i18n-tasks', '~> 0.8.3'
```

Copy default [configuration file](#configuration) (optional):
Copy the default [configuration file](#configuration):

```console
$ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
Expand Down Expand Up @@ -146,7 +146,7 @@ See the full list of tasks with `i18n-tasks --help`.

✔ Keys relative to the file path they are used in (see [relative roots configuration](#usage-search)) are supported.

Keys relative to `controller.action_name` in Rails controllers are not supported.
Keys relative to `controller.action_name` in Rails controllers are supported. The closest `def` name is used.

#### Plural keys

Expand Down Expand Up @@ -177,7 +177,7 @@ For now, you can disable dynamic key inference by passing `-s` or `--strict` to
Configuration is read from `config/i18n-tasks.yml` or `config/i18n-tasks.yml.erb`.
Inspect configuration with `i18n-tasks config`.

Install the default config file with:
Install the [default config file][config] with:

```console
$ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
Expand All @@ -188,60 +188,16 @@ Settings are compatible with Rails by default.
### Locales

By default, `base_locale` is set to `en` and `locales` are inferred from the paths to data files.
You can override these in the config:

```yaml
# config/i18n-tasks.yml
base_locale: en
locales: [es, fr] # This includes base_locale by default
```
`internal_locale` controls the language i18n-tasks reports in. Locales available are `en` and `ru` (pull request to add more!).

```yaml
internal_locale: en
```
You can override these in the [config][config].

### Storage

The default data adapter supports YAML and JSON files.

```yaml
# config/i18n-tasks.yml
data:
# configure YAML / JSON serializer options
# passed directly to load / dump / parse / serialize.
yaml:
write:
# do not wrap lines at 80 characters (override default)
line_width: -1
```

#### Multiple locale files

Use `data` options to work with locale data spread over multiple files.

`data.read` accepts a list of file globs to read from per-locale:

```
# config/i18n-tasks.yml
data:
read:
# read from namespaced files, e.g. simple_form.en.yml
- 'config/locales/*.%{locale}.yml'
# read from a gem (config is parsed with ERB first, then YAML)
- "<%= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml"
# default
- 'config/locales/%{locale}.yml'
```

#### Key pattern syntax

| syntax | description |
|:------------:|:----------------------------------------------------------|
| `*` | matches everything |
| `:` | matches a single key |
| `{a, b.c}` | match any in set, can use `:` and `*`, match is captured |
i18n-tasks can manage multiple translation files and read translations from other gems.
To find out more the `data` options in the [config][config].

For writing to locale files i18n-tasks provides 2 options.

Expand All @@ -266,7 +222,7 @@ data:

Conservative router keeps the keys where they are found, or infers the path from base locale.
If the key is completely new, conservative router will fall back to pattern router behaviour.
Conservative router is the default router.
Conservative router is the **default** router.

```
data:
Expand All @@ -276,55 +232,26 @@ data:
- 'config/locales/%{locale}.yml'
```

#### Custom adapters
If you store data somewhere but in the filesystem, e.g. in the database or mongodb, you can implement a custom adapter.
Implement [a handful of methods][adapter-example], then set `data.adapter` to the class name; the rest of the `data` config is passed to the initializer.
##### Key pattern syntax

```yaml
# config/i18n-tasks.yml
data:
# file_system is the default adapter, you can provide a custom class name here:
adapter: file_system
```
A special syntax similar to file glob patterns is used throughout i18n-tasks to match translation keys:

### Usage search
| syntax | description |
|:------------:|:----------------------------------------------------------|
| `*` | matches everything |
| `:` | matches a single key |
| `{a, b.c}` | match any in set, can use `:` and `*`, match is captured |


Configure usage search in `config/i18n-tasks.yml`:
#### Custom adapters

```yaml
# config/i18n-tasks.yml
# i18n usage search in source
search:
# search these directories (relative to your Rails.root directory, default: 'app/')
paths:
- 'app/'
- 'vendor/'
# paths for relative key resolution:
relative_roots:
# default:
- app/views
# add a custom one:
- app/views-mobile
# include only files matching this glob pattern (default: blank = include all files)
include:
- '*.rb'
- '*.html.*'
- '*.text.*'
# explicitly exclude files (default: exclude common binary files)
exclude:
- '*.js'
# you can override the default key regex pattern:
pattern: "\\bt[( ]\\s*(:?\".+?\"|:?'.+?'|:\\w+)"
# comments are ignored by default
ignore_lines:
- "^\\s*[#/](?!\\si18n-tasks-use)"
```
If you store data somewhere but in the filesystem, e.g. in the database or mongodb, you can implement a custom adapter.
If you have implemented a custom adapter please share it on [the wiki][wiki].

It is also possible to use a custom key usage scanner by setting `search.scanner` to a class name.
See this basic [pattern scanner](/lib/i18n/tasks/scanners/pattern_scanner.rb) for reference.
### Usage search

See the `search` section in the [config file][config] for all available configuration options.
An example of a custom scanner can be found here: https://github.com/glebm/i18n-tasks/issues/138#issuecomment-87255708.

### Fine-tuning

Expand All @@ -335,33 +262,8 @@ Add hints to static analysis with magic comment hints (lines starting with `(#|/
User.model_name.human
```

You can also explicitly ignore keys appearing in locale files:

```yaml
# config/i18n-tasks.yml
# do not report these keys as unused
ignore_unused:
- category.*.db_name
# do not report these keys as missing (both on blank value and no key)
ignore_missing:
- devise.errors.unauthorized # ignore this key
- pagination.views.* # ignore the whole pattern
# E.g to ignore all Rails number / currency keys:
- 'number.{format, percentage.format, precision.format, human.format, currency.format}.{strip_insignificant_zeros,significant,delimiter}'
- 'time.{pm,am}'
# do not report these keys when they have the same value as the base locale version
ignore_eq_base:
all:
- common.ok
es,fr:
- common.brand
# do not report these keys ever
ignore:
- kaminari.*
```
You can also explicitly ignore keys appearing in locale files via `ignore*` settings.
See the [config file][config] to find out more.

<a name="translation-config"></a>
### Google Translate
Expand All @@ -383,7 +285,7 @@ translation:
api_key: <Google Translate API key>
```
## Interactive Console
## Interactive console
`i18n-tasks irb` starts an IRB session in i18n-tasks context. Type `guide` for more information.

Expand All @@ -395,12 +297,7 @@ Export missing and unused data to XLSX:
$ i18n-tasks xlsx-report
```

### HTML

While i18n-tasks does not provide an HTML version of the report, you can add [one like this](https://gist.github.com/glebm/bdd3ab6d12d915f0c81b).


## Add New Tasks
## Add new tasks

Tasks that come with the gem are defined in [lib/i18n/tasks/command/commands](lib/i18n/tasks/command/commands).

Expand Down Expand Up @@ -430,6 +327,8 @@ Run with:
$ i18n-tasks my-task
```

See more examples of custom tasks [on the wiki](https://github.com/glebm/i18n-tasks/wiki#custom-tasks).

[MIT license]: /LICENSE.txt
[travis]: https://travis-ci.org/glebm/i18n-tasks
[badge-travis]: http://img.shields.io/travis/glebm/i18n-tasks.svg
Expand All @@ -439,6 +338,8 @@ $ i18n-tasks my-task
[badge-gemnasium]: https://gemnasium.com/glebm/i18n-tasks.svg
[code-climate]: https://codeclimate.com/github/glebm/i18n-tasks
[badge-code-climate]: http://img.shields.io/codeclimate/github/glebm/i18n-tasks.svg
[config]: https://github.com/glebm/i18n-tasks/blob/master/templates/config/i18n-tasks.yml
[wiki]: https://github.com/glebm/i18n-tasks/wiki "i18n-tasks wiki"
[i18n-gem]: https://github.com/svenfuchs/i18n "svenfuchs/i18n on Github"
[screenshot-find]: https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-usages.png "i18n-tasks find output screenshot"
[adapter-example]: https://github.com/glebm/i18n-tasks/blob/master/lib/i18n/tasks/data/file_system_base.rb
47 changes: 2 additions & 45 deletions bin/i18n-tasks
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,6 @@ if i18n_gem_config.respond_to?(:enforce_available_locales=) && i18n_gem_config.e
i18n_gem_config.enforce_available_locales = true
end

require 'i18n/tasks'
require 'i18n/tasks/commands'
require 'slop'
require 'i18n/tasks/cli'

err = proc { |message, exit_code|
if $stderr.isatty
$stderr.puts Term::ANSIColor.yellow('i18n-tasks: ' + message)
else
$stderr.puts message
end
exit exit_code
}

begin
ran = false
commander = ::I18n::Tasks::Commands
instance = commander.new
instance.set_internal_locale!
slop_adapter = ::I18n::Tasks::SlopCommand
args = ARGV.dup
args = ['--help'] if args.empty?
Slop.parse(args, help: true) do
on('-v', '--version', 'Print the version') {
puts I18n::Tasks::VERSION
exit
}
commander.cmds.each do |name, attr|
slop_dsl = slop_adapter.slop_command(name, attr) { |_name, opts|
begin
ran = true
instance.safe_run name, opts
rescue Errno::EPIPE
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
# i18n-tasks missing | head
exit 1
end
}
instance_exec(&slop_dsl)
end
end
rescue Slop::Error => e
err.call(e.message, 64)
end


err.call("Command unknown: #{args[0]}", 64) if !ran && args[0]
I18n::Tasks::CLI.start(ARGV)
Loading

0 comments on commit 22ea682

Please sign in to comment.