File: README.md

package info (click to toggle)
ruby-i18n-spec 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 224 kB
  • sloc: ruby: 478; makefile: 3
file content (74 lines) | stat: -rw-r--r-- 2,180 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# i18n-spec

[![Build Status](https://secure.travis-ci.org/tigrish/i18n-spec.png)](http://travis-ci.org/tigrish/i18n-spec)

i18n-spec provides RSpec matchers for testing your locale files and their translations.

## Testing the validity of your locale files

There are a few matchers available; the subject of the spec is always a path to a locale file.

    describe "config/locales/en.yml" do
      it { is_expected.to be_parseable }
      it { is_expected.to have_valid_pluralization_keys }
      it { is_expected.to_not have_missing_pluralization_keys }
      it { is_expected.to have_one_top_level_namespace }
      it { is_expected.to be_named_like_top_level_namespace }
      it { is_expected.to_not have_legacy_interpolations }
      it { is_expected.to have_a_valid_locale }
    end

All of these tests can be ran in one line with a shared example :

    describe "A locale file" do
      it_behaves_like 'a valid locale file', 'config/locales/en.yml'
    end

Even better, you can run all of these tests for every file in a directory like so :

    Dir.glob('config/locales/*.yml') do |locale_file|
      describe "a locale file" do
        it_behaves_like 'a valid locale file', locale_file
      end
    end

## Testing the validity of your translation data

To test that your locale file is a subset of the default locale file

	describe "config/locales/fr.yml" do
	  it { is_expected.to be_a_subset_of 'config/locales/en.yml' }
	end

If you need to test that all translations have been completed :

    describe "config/locales/fr.yml" do
      it { is_expected.to be_a_complete_translation_of 'config/locales/en.yml' }
    end

## Rake tasks

Include the tasks in your Rakefile with :

    require 'i18n-spec/tasks'

### Validating locale files

You can check a locale file with the following task :

    rake i18n-spec:validate FILEPATH

or check a whole directory :

    rake i18n-spec:validate DIRECTORY

### Checking for translation completeness


You can check a locale file with the following taks :

	rake i18n-spec:completeness SOURCE_FILEPATH TRANSLATED_FILEPATH

or again, check a whole directory :

	rake i18n-spec:completeness SOURCE_FILEPATH DIRECTORY