i18n-js 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.npmignore +1 -0
 - data/.travis.yml +4 -3
 - data/Appraisals +4 -0
 - data/CHANGELOG.md +21 -1
 - data/README.md +20 -13
 - data/app/assets/javascripts/i18n.js +2 -2
 - data/gemfiles/i18n_0_9.gemfile +7 -0
 - data/lib/i18n/js.rb +3 -0
 - data/lib/i18n/js/segment.rb +8 -4
 - data/lib/i18n/js/version.rb +1 -1
 - data/package.json +9 -1
 - data/spec/js/translate.spec.js +4 -0
 - data/spec/js/translations.js +4 -2
 - metadata +4 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1ebec2528bae57b4e38d4fbf4fe2241197dfc36d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5b5cc7647e6dabbd1fe607a438737f156b6e9e54
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 1e9b528236405cf0d44016d62ecbc892bd9ffec07e8266bd2cbd5760c17a852f95d38dd230779b1eab7a9db25c80394d4aa36231522227c51e5b28e2222a7ce0
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2fd596c5e48d2e570a930bf714278571c49944251247217b93f65a192338bbb3f72cf41d1f80bc8136a173792f2af705f1a97887a3ea1f182809c9f8d134f362
         
     | 
    
        data/.npmignore
    CHANGED
    
    
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -6,11 +6,11 @@ cache: 
     | 
|
| 
       6 
6 
     | 
    
         
             
              - bundler
         
     | 
| 
       7 
7 
     | 
    
         
             
            rvm:
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 2.1.10
         
     | 
| 
       9 
     | 
    
         
            -
              - 2.2. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 2.2.8
         
     | 
| 
       10 
10 
     | 
    
         
             
              # Since the Travis Build Env does not recognize `2.3` alias yet
         
     | 
| 
       11 
11 
     | 
    
         
             
              # We need to specify the version precisely
         
     | 
| 
       12 
     | 
    
         
            -
              - 2.3. 
     | 
| 
       13 
     | 
    
         
            -
              - 2.4. 
     | 
| 
      
 12 
     | 
    
         
            +
              - 2.3.5
         
     | 
| 
      
 13 
     | 
    
         
            +
              - 2.4.2
         
     | 
| 
       14 
14 
     | 
    
         
             
              - ruby-head
         
     | 
| 
       15 
15 
     | 
    
         
             
            before_install:
         
     | 
| 
       16 
16 
     | 
    
         
             
            # Need to install something extra to test JS
         
     | 
| 
         @@ -19,6 +19,7 @@ gemfile: 
     | 
|
| 
       19 
19 
     | 
    
         
             
              - gemfiles/i18n_0_6.gemfile
         
     | 
| 
       20 
20 
     | 
    
         
             
              - gemfiles/i18n_0_7.gemfile
         
     | 
| 
       21 
21 
     | 
    
         
             
              - gemfiles/i18n_0_8.gemfile
         
     | 
| 
      
 22 
     | 
    
         
            +
              - gemfiles/i18n_0_9.gemfile
         
     | 
| 
       22 
23 
     | 
    
         
             
            matrix:
         
     | 
| 
       23 
24 
     | 
    
         
             
              fast_finish: true
         
     | 
| 
       24 
25 
     | 
    
         
             
              allow_failures:
         
     | 
    
        data/Appraisals
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -18,6 +18,25 @@ This project adheres to [Semantic Versioning](http://semver.org/). 
     | 
|
| 
       18 
18 
     | 
    
         
             
            - Nothing
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         | 
| 
      
 21 
     | 
    
         
            +
            ## [3.0.2] - 2017-10-26
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ### Added
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            - Nothing
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ### Changed
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            - [Ruby] Avoid writing new file if a file with same content already exists  
         
     | 
| 
      
 30 
     | 
    
         
            +
              (PR: https://github.com/fnando/i18n-js/pull/473)
         
     | 
| 
      
 31 
     | 
    
         
            +
            - [JS] Fix fallback when "3-part" locale like `zh-Hant-TW` is used  
         
     | 
| 
      
 32 
     | 
    
         
            +
              It was falling back to `zh` first instead of `zh-Hant` (see new test case added)  
         
     | 
| 
      
 33 
     | 
    
         
            +
              (PR: https://github.com/fnando/i18n-js/pull/475)
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            ### Fixed
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            - Nothing
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       21 
40 
     | 
    
         
             
            ## [3.0.1] - 2017-08-02
         
     | 
| 
       22 
41 
     | 
    
         | 
| 
       23 
42 
     | 
    
         
             
            ### Changed
         
     | 
| 
         @@ -251,7 +270,8 @@ And today is not April Fools' Day 
     | 
|
| 
       251 
270 
     | 
    
         | 
| 
       252 
271 
     | 
    
         | 
| 
       253 
272 
     | 
    
         | 
| 
       254 
     | 
    
         
            -
            [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0. 
     | 
| 
      
 273 
     | 
    
         
            +
            [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0.2...HEAD
         
     | 
| 
      
 274 
     | 
    
         
            +
            [3.0.2]:      https://github.com/fnando/i18n-js/compare/v3.0.1...v3.0.2
         
     | 
| 
       255 
275 
     | 
    
         
             
            [3.0.1]:      https://github.com/fnando/i18n-js/compare/v3.0.0...v3.0.1
         
     | 
| 
       256 
276 
     | 
    
         
             
            [3.0.0]:      https://github.com/fnando/i18n-js/compare/v3.0.0.rc16...v3.0.0
         
     | 
| 
       257 
277 
     | 
    
         
             
            [3.0.0.rc16]: https://github.com/fnando/i18n-js/compare/v3.0.0.rc15...v3.0.0.rc16
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -21,7 +21,7 @@ Features: 
     | 
|
| 
       21 
21 
     | 
    
         
             
            - Lots more! :)
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
            ## Version Notice
         
     | 
| 
       24 
     | 
    
         
            -
            The `master` branch (including this README) is for latest `3.0.0 
     | 
| 
      
 24 
     | 
    
         
            +
            The `master` branch (including this README) is for latest `3.0.0` instead of `2.x`.
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            ## Usage
         
     | 
| 
         @@ -279,9 +279,15 @@ by hand or using your favorite programming language. More info below. 
     | 
|
| 
       279 
279 
     | 
    
         | 
| 
       280 
280 
     | 
    
         
             
            #### Via NPM with webpack and CommonJS
         
     | 
| 
       281 
281 
     | 
    
         | 
| 
       282 
     | 
    
         
            -
             
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
            Add the following line to your package.json dependencies  
         
     | 
| 
      
 284 
     | 
    
         
            +
            where version is the version you want  
         
     | 
| 
       283 
285 
     | 
    
         
             
            ```javascript
         
     | 
| 
       284 
     | 
    
         
            -
            "i18n-js": " 
     | 
| 
      
 286 
     | 
    
         
            +
            "i18n-js": "{version_constraint}"
         
     | 
| 
      
 287 
     | 
    
         
            +
             
     | 
| 
      
 288 
     | 
    
         
            +
            // Or if you want unreleased version
         
     | 
| 
      
 289 
     | 
    
         
            +
            // npm install requires it to be the gzipped tarball, see [npm install](https://www.npmjs.org/doc/cli/npm-install.html)
         
     | 
| 
      
 290 
     | 
    
         
            +
            "i18n-js": "https://github.com/fnando/i18n-js/archive/{tag_name_or_branch_name_or_commit_sha}.tar.gz"
         
     | 
| 
       285 
291 
     | 
    
         
             
            ```
         
     | 
| 
       286 
292 
     | 
    
         
             
            Run npm install then use via
         
     | 
| 
       287 
293 
     | 
    
         
             
            ```javascript
         
     | 
| 
         @@ -777,19 +783,20 @@ Due to the design of `sprockets`: 
     | 
|
| 
       777 
783 
     | 
    
         
             
            This means that new locale files will not be detected, and so they will not trigger a i18n-js refresh. There are a few approaches to work around this:
         
     | 
| 
       778 
784 
     | 
    
         | 
| 
       779 
785 
     | 
    
         
             
            1. You can force i18n-js to update its translations by completely clearing the assets cache. Use one of the following:
         
     | 
| 
      
 786 
     | 
    
         
            +
              
         
     | 
| 
      
 787 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 788 
     | 
    
         
            +
            $ rake assets:clobber
         
     | 
| 
      
 789 
     | 
    
         
            +
            # Or, with older versions of Rails:
         
     | 
| 
      
 790 
     | 
    
         
            +
            $ rake tmp:cache:clear
         
     | 
| 
      
 791 
     | 
    
         
            +
            ```
         
     | 
| 
       780 
792 
     | 
    
         | 
| 
       781 
     | 
    
         
            -
             
     | 
| 
       782 
     | 
    
         
            -
              $ rake assets:clobber
         
     | 
| 
       783 
     | 
    
         
            -
              # Or, with older versions of Rails:
         
     | 
| 
       784 
     | 
    
         
            -
              $ rake tmp:cache:clear
         
     | 
| 
       785 
     | 
    
         
            -
              ```
         
     | 
| 
      
 793 
     | 
    
         
            +
            These commands will remove *all* fingerprinted assets, and you will have to recompile them with
         
     | 
| 
       786 
794 
     | 
    
         | 
| 
       787 
     | 
    
         
            -
             
     | 
| 
      
 795 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 796 
     | 
    
         
            +
            $ rake assets:precompile
         
     | 
| 
      
 797 
     | 
    
         
            +
            ```
         
     | 
| 
       788 
798 
     | 
    
         | 
| 
       789 
     | 
    
         
            -
             
     | 
| 
       790 
     | 
    
         
            -
                $ rake assets:precompile
         
     | 
| 
       791 
     | 
    
         
            -
                ```
         
     | 
| 
       792 
     | 
    
         
            -
                or similar commands.  If you are precompiling assets on the target machine(s), cached pages may be broken by this, so they will need to be refreshed.
         
     | 
| 
      
 799 
     | 
    
         
            +
            or similar commands.  If you are precompiling assets on the target machine(s), cached pages may be broken by this, so they will need to be refreshed.
         
     | 
| 
       793 
800 
     | 
    
         | 
| 
       794 
801 
     | 
    
         
             
            2. You can change something in a different locale file.
         
     | 
| 
       795 
802 
     | 
    
         | 
| 
         @@ -309,11 +309,11 @@ 
     | 
|
| 
       309 
309 
     | 
    
         
             
                  var firstFallback = null;
         
     | 
| 
       310 
310 
     | 
    
         
             
                  var secondFallback = null;
         
     | 
| 
       311 
311 
     | 
    
         
             
                  if (localeParts.length === 3) {
         
     | 
| 
       312 
     | 
    
         
            -
                    firstFallback =  
     | 
| 
       313 
     | 
    
         
            -
                    secondFallback = [
         
     | 
| 
      
 312 
     | 
    
         
            +
                    firstFallback = [
         
     | 
| 
       314 
313 
     | 
    
         
             
                      localeParts[0],
         
     | 
| 
       315 
314 
     | 
    
         
             
                      localeParts[1]
         
     | 
| 
       316 
315 
     | 
    
         
             
                    ].join("-");
         
     | 
| 
      
 316 
     | 
    
         
            +
                    secondFallback = localeParts[0];
         
     | 
| 
       317 
317 
     | 
    
         
             
                  }
         
     | 
| 
       318 
318 
     | 
    
         
             
                  else if (localeParts.length === 2) {
         
     | 
| 
       319 
319 
     | 
    
         
             
                    firstFallback = localeParts[0];
         
     | 
    
        data/lib/i18n/js.rb
    CHANGED
    
    | 
         @@ -219,6 +219,9 @@ module I18n 
     | 
|
| 
       219 
219 
     | 
    
         
             
                    FileUtils.mkdir_p(export_i18n_js_dir_path)
         
     | 
| 
       220 
220 
     | 
    
         | 
| 
       221 
221 
     | 
    
         
             
                    i18n_js_path = File.expand_path('../../../app/assets/javascripts/i18n.js', __FILE__)
         
     | 
| 
      
 222 
     | 
    
         
            +
                    destination_path = File.expand_path("i18n.js", export_i18n_js_dir_path)
         
     | 
| 
      
 223 
     | 
    
         
            +
                    return if File.exist?(destination_path) && FileUtils.identical?(i18n_js_path, destination_path)
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
       222 
225 
     | 
    
         
             
                    FileUtils.cp(i18n_js_path, export_i18n_js_dir_path)
         
     | 
| 
       223 
226 
     | 
    
         
             
                  end
         
     | 
| 
       224 
227 
     | 
    
         | 
    
        data/lib/i18n/js/segment.rb
    CHANGED
    
    | 
         @@ -40,11 +40,15 @@ module I18n 
     | 
|
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                  def write_file(_file = @file, _translations = @translations)
         
     | 
| 
       42 
42 
     | 
    
         
             
                    FileUtils.mkdir_p File.dirname(_file)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    contents = js_header
         
     | 
| 
      
 44 
     | 
    
         
            +
                    _translations.each do |locale, translations_for_locale|
         
     | 
| 
      
 45 
     | 
    
         
            +
                      contents << js_translations(locale, translations_for_locale)
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    return if File.exist?(_file) && File.read(_file) == contents
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
       43 
50 
     | 
    
         
             
                    File.open(_file, "w+") do |f|
         
     | 
| 
       44 
     | 
    
         
            -
                      f <<  
     | 
| 
       45 
     | 
    
         
            -
                      _translations.each do |locale, translations_for_locale|
         
     | 
| 
       46 
     | 
    
         
            -
                        f << js_translations(locale, translations_for_locale)
         
     | 
| 
       47 
     | 
    
         
            -
                      end
         
     | 
| 
      
 51 
     | 
    
         
            +
                      f << contents
         
     | 
| 
       48 
52 
     | 
    
         
             
                    end
         
     | 
| 
       49 
53 
     | 
    
         
             
                  end
         
     | 
| 
       50 
54 
     | 
    
         | 
    
        data/lib/i18n/js/version.rb
    CHANGED
    
    
    
        data/package.json
    CHANGED
    
    | 
         @@ -1,6 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "i18n-js",
         
     | 
| 
       3 
     | 
    
         
            -
              "version": "3.0. 
     | 
| 
      
 3 
     | 
    
         
            +
              "version": "3.0.2",
         
     | 
| 
      
 4 
     | 
    
         
            +
              "description": "A javascript library similar to Ruby on Rails i18n gem",
         
     | 
| 
      
 5 
     | 
    
         
            +
              "author": "Nando Vieira",
         
     | 
| 
      
 6 
     | 
    
         
            +
              "license": "MIT",
         
     | 
| 
      
 7 
     | 
    
         
            +
              "keywords": ["i18n"],
         
     | 
| 
       4 
8 
     | 
    
         
             
              "devDependencies": {
         
     | 
| 
       5 
9 
     | 
    
         
             
                "jasmine-node": "^1.14.5"
         
     | 
| 
       6 
10 
     | 
    
         
             
              },
         
     | 
| 
         @@ -8,6 +12,10 @@ 
     | 
|
| 
       8 
12 
     | 
    
         
             
              "scripts": {
         
     | 
| 
       9 
13 
     | 
    
         
             
                "test": "./node_modules/.bin/jasmine-node spec/js"
         
     | 
| 
       10 
14 
     | 
    
         
             
              },
         
     | 
| 
      
 15 
     | 
    
         
            +
              "homepage": "https://github.com/fnando/i18n-js",
         
     | 
| 
      
 16 
     | 
    
         
            +
              "bugs": {
         
     | 
| 
      
 17 
     | 
    
         
            +
                "url": "https://github.com/fnando/i18n-js/issues"
         
     | 
| 
      
 18 
     | 
    
         
            +
              },
         
     | 
| 
       11 
19 
     | 
    
         
             
              "repository": {
         
     | 
| 
       12 
20 
     | 
    
         
             
                "type": "git",
         
     | 
| 
       13 
21 
     | 
    
         
             
                "url": "https://github.com/fnando/i18n-js.git"
         
     | 
    
        data/spec/js/translate.spec.js
    CHANGED
    
    | 
         @@ -96,6 +96,10 @@ describe("Translate", function(){ 
     | 
|
| 
       96 
96 
     | 
    
         
             
                it("fallbacks to 1-part locale when 2-part missing requested translation", function(){
         
     | 
| 
       97 
97 
     | 
    
         
             
                  expect(I18n.t("dog")).toEqual("狗");
         
     | 
| 
       98 
98 
     | 
    
         
             
                });
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                it("fallbacks to 2-part for the first time", function(){
         
     | 
| 
      
 101 
     | 
    
         
            +
                  expect(I18n.t("dragon")).toEqual("龍");
         
     | 
| 
      
 102 
     | 
    
         
            +
                });
         
     | 
| 
       99 
103 
     | 
    
         
             
              });
         
     | 
| 
       100 
104 
     | 
    
         | 
| 
       101 
105 
     | 
    
         
             
              it("fallbacks using custom rules (function)", function(){
         
     | 
    
        data/spec/js/translations.js
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: i18n-js
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 3.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Nando Vieira
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-10-26 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: i18n
         
     | 
| 
         @@ -109,6 +109,7 @@ files: 
     | 
|
| 
       109 
109 
     | 
    
         
             
            - gemfiles/i18n_0_6.gemfile
         
     | 
| 
       110 
110 
     | 
    
         
             
            - gemfiles/i18n_0_7.gemfile
         
     | 
| 
       111 
111 
     | 
    
         
             
            - gemfiles/i18n_0_8.gemfile
         
     | 
| 
      
 112 
     | 
    
         
            +
            - gemfiles/i18n_0_9.gemfile
         
     | 
| 
       112 
113 
     | 
    
         
             
            - i18n-js.gemspec
         
     | 
| 
       113 
114 
     | 
    
         
             
            - lib/i18n-js.rb
         
     | 
| 
       114 
115 
     | 
    
         
             
            - lib/i18n/js.rb
         
     | 
| 
         @@ -197,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       197 
198 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       198 
199 
     | 
    
         
             
            requirements: []
         
     | 
| 
       199 
200 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       200 
     | 
    
         
            -
            rubygems_version: 2.6. 
     | 
| 
      
 201 
     | 
    
         
            +
            rubygems_version: 2.6.13
         
     | 
| 
       201 
202 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       202 
203 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       203 
204 
     | 
    
         
             
            summary: It's a small library to provide the Rails I18n translations on the Javascript.
         
     |