Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (39 commits)
  Tidy up the spec template indentation, use let(:unused_keys).
  Update README.md
  Added Gitter badge
  minor fix ignore_lines pattern
  travis: 2.1.1 -> 2.1.3
  .travis latest jruby
  Bump to 0.7.8
  Google Translate fixnum spec glebm#100
  Improve ignore_lines glebm#96 glebm#102
  initialize @key_filter glebm#101
  Lines in HAML that start with # are skipped
  ignore config: better examples
  ru copy fix
  move error message to i18n
  YARD signatures for GoogleTranslation methods
  Possible fix for glebm#99
  README: small fixes for defining custom commands
  Remove unused keys
  fix typo in gemspec [ci skip]
  Simplify commands DSL i18n
  ...

Conflicts:
	spec/google_translate_spec.rb
  • Loading branch information
bartimaeus committed Dec 1, 2014
2 parents 740719c + 75e40a2 commit d7b7cc0
Show file tree
Hide file tree
Showing 44 changed files with 525 additions and 383 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: ruby
rvm:
- 2.1.1
- 2.1.3
- 2.0.0
- 1.9.3
- jruby-1.7.13
- jruby
- rbx-2.2.10
env:
global:
Expand Down
16 changes: 16 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.7.8

* Fix Google Translate issues with non-string keys [#100](https://github.com/glebm/i18n-tasks/pull/100)
* Fix an issue with certain HAML not being parsed [#96](https://github.com/glebm/i18n-tasks/issues/96) [#102](https://github.com/glebm/i18n-tasks/pull/102)
* Fix other minor issues

## 0.7.7

* Fix regression: keys are sorted once again [#92](https://github.com/glebm/i18n-tasks/issues/92).

## 0.7.6

* Add a post-install notice with setup commands
* Fix a small typo in the config template [#91](https://github.com/glebm/i18n-tasks/pull/91).
* Fix `find` crashing on relative keys (regression)

## 0.7.5

Dynamic key usage inference fixes by [Mikko Koski](https://github.com/rap1ds):
Expand Down
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
# i18n-tasks [![Build Status][badge-travis]][travis] [![Coverage Status][badge-coverage]][coverage] [![Code Climate][badge-code-climate]][code-climate] [![Gemnasium][badge-gemnasium]][gemnasium]
# i18n-tasks [![Build Status][badge-travis]][travis] [![Coverage Status][badge-coverage]][coverage] [![Code Climate][badge-code-climate]][code-climate] [![Gemnasium][badge-gemnasium]][gemnasium] [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/glebm/i18n-tasks?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

i18n-tasks helps you find and manage missing and unused translations.

## What?

i18n-tasks scans calls such as `I18n.t('some.key')` and provides reports on key usage, missing, and unused keys.
i18n-tasks can also can pre-fill missing keys, including from Google Translate, and it can remove unused keys as well.
<img width="539" height="331" src="https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-tasks.png">

## Why?
This gem analyses code statically for key usages, such as `I18n.t('some.key')`, in order to:

The default approach to locale data management with gems such as [i18n][i18n-gem] is flawed.
If you use a key that does not exist, this will only blow up at runtime. Keys left over from removed code accumulate
in the resource files and introduce unnecessary overhead on the translators. Translation files can quickly turn to disarray.
* Report keys that are missing or unused.
* Pre-fill missing keys, optionally from Google Translate.
* Remove unused keys.

i18n-tasks improves this by analysing code statically, without running it. It scans calls such as `I18n.t('some.key')` and provides reports on key usage, missing, and unused keys.
It can also pre-fill missing keys, including from Google Translate, and it can remove unused keys as well.
Thus addressing the two main problems of [i18n gem][i18n-gem] design:

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

<img width="539" height="331" src="https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-tasks.png">
* Missing keys only blow up at runtime.
* Keys no longer in use may accumulate and introduce overhead, without you knowing it.

## Installation

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

Add it to the Gemfile:

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

Copy default [configuration file](#configuration) (optional):
Expand Down Expand Up @@ -117,7 +114,7 @@ Sort the keys:
$ i18n-tasks normalize
```

Sort the keys, and move them to the respective files as defined by (`config.write`)[#multiple-locale-files]:
Sort the keys, and move them to the respective files as defined by [`config.write`](#multiple-locale-files):

```console
$ i18n-tasks normalize -p
Expand Down Expand Up @@ -411,7 +408,7 @@ Add a custom task like the ones defined by the gem:

```ruby
# my_commands.rb
class MyCommands
module MyCommands
include ::I18n::Tasks::Command::Collection
cmd :my_task, desc: 'my custom task'
def my_task(opts = {})
Expand All @@ -422,7 +419,7 @@ end
```yaml
# config/i18n-tasks.yml
<%
require 'my_commands'
require './my_commands'
I18n::Tasks::Commands.send :include, MyCommands
%>
```
Expand Down
6 changes: 3 additions & 3 deletions bin/i18n-tasks
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require 'i18n/tasks/commands'
require 'slop'

err = proc { |message, exit_code|
if STDERR.isatty
STDERR.puts Term::ANSIColor.yellow('i18n-tasks: ' + message)
if $stderr.isatty
$stderr.puts Term::ANSIColor.yellow('i18n-tasks: ' + message)
else
STDERR.puts message
$stderr.puts message
end
exit exit_code
}
Expand Down
9 changes: 4 additions & 5 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# i18n-tasks works on itself! this is the internal config

# This is not the default config for new apps, but is the internal config for i18n-tasks to analyze itself.
# You can find the default config here: https://github.com/glebm/i18n-tasks/blob/master/templates/config/i18n-tasks.yml

base_locale: en
## i18n-tasks detects locales automatically from the existing locale files
## uncomment to set locales explicitly
Expand All @@ -22,7 +25,7 @@ data:
# key => file routes, matched top to bottom
write:
## E.g., write devise and simple form keys to their respective files
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale.yml}']
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
# Catch-all
- config/locales/%{locale}.yml
# `i18n-tasks normalize -p` will force move the keys according to these rules
Expand Down Expand Up @@ -59,10 +62,6 @@ search:
## Or, File.fnmatch patterns to include
# include: ["*.rb", "*.html.slim"]

## Lines starting with # or / are ignored by default
# ignore_lines:
# - "^\\s*[#/](?!\\si18n-tasks-use)"

## Google Translate
# translation:
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
Expand Down
155 changes: 78 additions & 77 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,102 +1,103 @@
---
en:
i18n_tasks:
common:
locale: Locale
type: Type
key: Key
value: Value
base_value: Base Value
details: Details
continue_q: Continue?
n_more: "%{count} more"
google_translate:
errors:
no_results: Google Translate returned no results. Make sure billing information is set at
https://code.google.com/apis/console.
remove_unused:
confirm:
one: One translations will be removed from %{locales}.
other: "%{count} translation will be removed from %{locales}."
removed: Removed %{count} keys
noop: No unused keys to remove
translate_missing:
translated: Translated %{count} keys
add_missing:
added: Added %{count} keys
unused:
none: Every translation is in use.
missing:
none: No translations are missing.
usages:
none: No key usages found.
health:
no_keys_detected: No keys detected. Check data.read in config/i18n-tasks.yml.
data_stats:
title: Forest (%{locales})
text: has %{key_count} keys across %{locale_count} locales. On average, values are %{value_chars_avg}
characters long, keys have %{key_segments_avg} segments, a locale has %{per_locale_avg} keys.
text_single_locale: has %{key_count} keys in total. On average, values are %{value_chars_avg}
characters long, keys have %{key_segments_avg} segments.
cmd:
encourage:
- Good job!
- Well done!
- Perfect!
args:
default_all: 'Default: all'
default_text: 'Default: %{value}'
desc:
confirm: Confirm automatically
data_format: 'Data format: %{valid_text}. %{default_text}.'
key_pattern: Filter by key pattern (e.g. 'common.*')
key_pattern_to_rename: Full key (pattern) to rename. Required
locale: 'Locale. Default: base'
locale_to_translate_from: 'Locale to translate from (default: base)'
locales_filter: 'Comma-separated list of locale(s) to process. Default: all. Special: base.'
missing_types: 'Filter by types: %{valid}. Default: all'
new_key_name: New name, interpolates original name as %{key}. Required
nostdin: Do not read from stdin
out_format: 'Output format: %{valid_text}. %{default_text}.'
pattern_router: 'Use pattern router: keys moved per config data.write'
strict: Do not infer dynamic key usage such as `t("category.\#{category.name}")`
value: 'Value. Interpolates: %{value}, %{human_key}, %{value_or_human_key}'
desc:
normalize: 'normalize translation data: sort and move to the right files'
add_missing: add missing keys to locale data
config: display i18n-tasks configuration
data: show locale data
data_merge: merge locale data with trees
data_write: replace locale data with tree
data_remove: remove keys present in tree from data
health: is everything OK?
data_write: replace locale data with tree
eq_base: show translations equal to base value
find: show where keys are used in the code
unused: show unused translations
gem_path: show path to the gem
health: is everything OK?
irb: start REPL session within i18n-tasks context
missing: show missing translations
translate_missing: translate missing keys with Google Translate
add_missing: add missing keys to locale data
normalize: 'normalize translation data: sort and move to the right files'
remove_unused: remove unused keys
eq_base: show translations equal to base value
tree_translate: Google Translate a tree to root locales
tree_merge: merge trees
translate_missing: translate missing keys with Google Translate
tree_convert: convert tree between formats
tree_filter: filter tree by key pattern
tree_merge: merge trees
tree_rename_key: rename tree node
tree_subtract: tree A minus the keys in tree B
tree_set_value: set values of keys, optionally match a pattern
tree_convert: convert tree between formats
config: display i18n-tasks configuration
gem_path: show path to the gem
irb: start REPL session within i18n-tasks context
tree_subtract: tree A minus the keys in tree B
tree_translate: Google Translate a tree to root locales
unused: show unused translations
xlsx_report: save missing and unused translations to an Excel file
args:
default_text: 'Default: %{value}'
default_all: 'Default: all'
desc:
out_format: 'Output format: %{valid_text}. %{default_text}.'
data_format: 'Data format: %{valid_text}. %{default_text}.'
keys: List of keys separated by commas (,), spaces, or newlines.
locales_filter: 'Comma-separated list of locale(s) to process. Default: all. Special: base.'
locale: 'Locale. Default: base'
locale_to_translate_from: 'Locale to translate from (default: base)'
confirm: Confirm automatically
nostdin: Do not read from stdin
strict: Do not infer dynamic key usage such as `t("category.\#{category.name}")`
missing_types: 'Filter by types: %{valid}. Default: all'
key_pattern: Filter by key pattern (e.g. 'common.*')
key_pattern_to_rename: Full key (pattern) to rename. Required
new_key_name: New name, interpolates original name as %{key}. Required
value: 'Value. Interpolates: %{value}, %{human_key}, %{value_or_human_key}'
pattern_router: 'Use pattern router: keys moved per config data.write'
enum_opt:
desc: "%{valid_text}. %{default_text}"
invalid: "%{invalid} is not one of: %{valid}."
encourage:
- Good job!
- Well done!
- Perfect!
enum_list_opt:
desc: 'Comma-separated list of: %{valid_text}. %{default_text}'
invalid: "%{invalid} is not in: %{valid}."
enum_opt:
desc: "%{valid_text}. %{default_text}"
invalid: "%{invalid} is not one of: %{valid}."
errors:
pass_forest: Pass locale forest
invalid_locale: Invalid locale %{invalid}
invalid_format: 'Unknown format %{invalid}. Valid: %{valid}.'
invalid_locale: Invalid locale %{invalid}
invalid_missing_type:
one: 'Unknown type %{invalid}. Valid: %{valid}.'
other: 'Unknown types: %{invalid}. Valid: %{valid}.'
pass_forest: Pass locale forest
common:
base_value: Base Value
continue_q: Continue?
details: Details
key: Key
locale: Locale
n_more: "%{count} more"
type: Type
value: Value
data_stats:
text: has %{key_count} keys across %{locale_count} locales. On average, values are %{value_chars_avg}
characters long, keys have %{key_segments_avg} segments, a locale has %{per_locale_avg} keys.
text_single_locale: has %{key_count} keys in total. On average, values are %{value_chars_avg}
characters long, keys have %{key_segments_avg} segments.
title: Forest (%{locales})
google_translate:
errors:
no_api_key: Set Google API key via GOOGLE_TRANSLATE_API_KEY environment variable or translation.api_key
in config/i18n-tasks.yml. Get the key at https://code.google.com/apis/console.
no_results: Google Translate returned no results. Make sure billing information is set at
https://code.google.com/apis/console.
health:
no_keys_detected: No keys detected. Check data.read in config/i18n-tasks.yml.
missing:
none: No translations are missing.
remove_unused:
confirm:
one: One translations will be removed from %{locales}.
other: "%{count} translation will be removed from %{locales}."
noop: No unused keys to remove
removed: Removed %{count} keys
translate_missing:
translated: Translated %{count} keys
unused:
none: Every translation is in use.
usages:
none: No key usages found.
Loading

0 comments on commit d7b7cc0

Please sign in to comment.