tolken 0.2.0 → 0.3.0
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/Gemfile.lock +1 -1
 - data/README.md +25 -6
 - data/lib/tolken/{simle_form.rb → simple_form.rb} +0 -0
 - data/lib/tolken/translates.rb +6 -3
 - data/lib/tolken/version.rb +1 -1
 - data/tolken.gemspec +2 -2
 - metadata +5 -5
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9e3b810d92ead0e93a5131e336d22f2f66425549eb0df62a013b27506450d086
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8137c3c286daf8052cc07584d01ddffc3db1f5a2e1e2379f88bc2d73b032c081
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9578b5db99672f9c51af74dea5d88b8640c2420cd635a12dffcf95151af7d660be82ca7286119a1a50319029d51bdde0b8b63a71c1985bf4ea802b0736555413
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c8d80d8c6a40691716920b95e5bd4dcb4f028edd9b9ddc76e9471df5a691be3a9dd3c061ff948673a424a61e054d584b9272de033d64badadaeb7e8b4053ef01
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,9 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Tolken
         
     | 
| 
       2 
2 
     | 
    
         
             
            Tolken is a Ruby on Rails Gem that allows you to translate database fields using Postgres' jsob data type.
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            Tolken's API is more verbose than most similar gems. The  
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            In Tolken a translatable field is just a Ruby hash which makes it easy to reason about. See *Usage* for details.
         
     | 
| 
      
 4 
     | 
    
         
            +
            Tolken's API is more verbose than most similar gems. The idea is that you should be aware of when you're dealing with translatable fields and what language you're interested in in any given moment.  In Tolken a translatable field is just a Ruby hash which makes it easy to reason about. See *Usage* for details.
         
     | 
| 
       7 
5 
     | 
    
         | 
| 
       8 
6 
     | 
    
         
             
            [](https://travis-ci.org/varvet/tolken)
         
     | 
| 
       9 
7 
     | 
    
         
             
            [](https://codeclimate.com/github/varvet/tolken/maintainability)
         
     | 
| 
         @@ -68,7 +66,11 @@ post = Post.create(title: { en: "News", sv: "Nyheter" }) 
     | 
|
| 
       68 
66 
     | 
    
         
             
            post.title # => { en: "News", sv: "Nyheter" }
         
     | 
| 
       69 
67 
     | 
    
         
             
            post.title(:en) # => "News"
         
     | 
| 
       70 
68 
     | 
    
         
             
            post.title(:sv) # => "Nyheter"
         
     | 
| 
      
 69 
     | 
    
         
            +
            post.title("sv") # => "Nyheter"
         
     | 
| 
      
 70 
     | 
    
         
            +
            post.title[:en] # => "News"
         
     | 
| 
      
 71 
     | 
    
         
            +
            post.title["en"] # => "News"
         
     | 
| 
       71 
72 
     | 
    
         
             
            post.title(:dk) # ArgumentError, "Invalid locale dk"
         
     | 
| 
      
 73 
     | 
    
         
            +
            post.title[:dk] # => nil
         
     | 
| 
       72 
74 
     | 
    
         
             
            post.title(:de) # => nil
         
     | 
| 
       73 
75 
     | 
    
         | 
| 
       74 
76 
     | 
    
         
             
            post.title = { en: "News", sv: "Nyheter" }
         
     | 
| 
         @@ -91,10 +93,10 @@ post.errors.messages # => { name_sv: ["can't be blank"] } 
     | 
|
| 
       91 
93 
     | 
    
         
             
            Tolken checks that all `I18n.available_locales` has present values.
         
     | 
| 
       92 
94 
     | 
    
         | 
| 
       93 
95 
     | 
    
         
             
            ### View Forms
         
     | 
| 
       94 
     | 
    
         
            -
            Tolken  
     | 
| 
      
 96 
     | 
    
         
            +
            While creating form inputs for your locale versions are as simple as adding `[<locale>]` to the html name attribute Tolken provides opt-in support for integrating with [SimpleForm](https://github.com/plataformatec/simple_form). To opt-in update your Gemfile:
         
     | 
| 
       95 
97 
     | 
    
         | 
| 
       96 
98 
     | 
    
         
             
            ```ruby
         
     | 
| 
       97 
     | 
    
         
            -
            gem "tolken", require: "tolken/ 
     | 
| 
      
 99 
     | 
    
         
            +
            gem "tolken", require: "tolken/simple_form"
         
     | 
| 
       98 
100 
     | 
    
         
             
            ```
         
     | 
| 
       99 
101 
     | 
    
         | 
| 
       100 
102 
     | 
    
         
             
            Now if you add a simple_form field for a translatable field SimpleForm will generate an input per language version:
         
     | 
| 
         @@ -112,6 +114,19 @@ By default a text input field is generated. If you want another type you can ove 
     | 
|
| 
       112 
114 
     | 
    
         
             
            <%= form.input :title, type: :text %>
         
     | 
| 
       113 
115 
     | 
    
         
             
            ```
         
     | 
| 
       114 
116 
     | 
    
         | 
| 
      
 117 
     | 
    
         
            +
            Without simple form your inputs might look something like:
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
            ```html
         
     | 
| 
      
 120 
     | 
    
         
            +
            <input name="post[title][en]" id="post_title_en">
         
     | 
| 
      
 121 
     | 
    
         
            +
            <input name="post[title][sv]" id="post_title_sv">
         
     | 
| 
      
 122 
     | 
    
         
            +
            ```
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
            Don't forget whitelist the nested locale params in your controller:
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
            ```rb
         
     | 
| 
      
 127 
     | 
    
         
            +
            params.require(:post).permit(title: I18n.available_locales)
         
     | 
| 
      
 128 
     | 
    
         
            +
            ```
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
       115 
130 
     | 
    
         
             
            This will instead render one text area per language version.
         
     | 
| 
       116 
131 
     | 
    
         | 
| 
       117 
132 
     | 
    
         
             
            The specs for [translates](spec/tolken/translates_spec.rb) is a good resource of additional usage examples.
         
     | 
| 
         @@ -127,7 +142,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run 
     | 
|
| 
       127 
142 
     | 
    
         
             
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         
     | 
| 
       128 
143 
     | 
    
         | 
| 
       129 
144 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       130 
     | 
    
         
            -
            Bug reports and pull requests are welcome on GitHub at https://github.com/varvet/tolken. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 
     | 
| 
      
 145 
     | 
    
         
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/varvet/tolken. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
            If you use and like Tolken but find yourself adding features that you're missing in Tolken please consider submitting a pull request!
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
            To create a pull request follow these steps:
         
     | 
| 
       131 
150 
     | 
    
         | 
| 
       132 
151 
     | 
    
         
             
                $ git clone git@github.com:varvet/tolken.git
         
     | 
| 
       133 
152 
     | 
    
         
             
                $ cd tolken
         
     | 
| 
         
            File without changes
         
     | 
    
        data/lib/tolken/translates.rb
    CHANGED
    
    | 
         @@ -7,7 +7,10 @@ module Tolken 
     | 
|
| 
       7 
7 
     | 
    
         
             
                  serialize(field_name, HashSerializer)
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                  if options[:presence]
         
     | 
| 
       10 
     | 
    
         
            -
                     
     | 
| 
      
 10 
     | 
    
         
            +
                    validation_names = I18n.available_locales.map { |locale| "#{field_name}_#{locale}" }
         
     | 
| 
      
 11 
     | 
    
         
            +
                    readers = store_accessor(field_name, *validation_names)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    private(*(readers + readers.map { |name| "#{name}=" }))
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       11 
14 
     | 
    
         
             
                    define_validator(field_name) if options[:presence]
         
     | 
| 
       12 
15 
     | 
    
         
             
                  end
         
     | 
| 
       13 
16 
     | 
    
         
             
                end
         
     | 
| 
         @@ -16,10 +19,10 @@ module Tolken 
     | 
|
| 
       16 
19 
     | 
    
         | 
| 
       17 
20 
     | 
    
         
             
                def define_getter(field_name)
         
     | 
| 
       18 
21 
     | 
    
         
             
                  define_method(field_name) do |locale = nil|
         
     | 
| 
       19 
     | 
    
         
            -
                    return self[field_name 
     | 
| 
      
 22 
     | 
    
         
            +
                    return self[field_name] unless locale
         
     | 
| 
       20 
23 
     | 
    
         | 
| 
       21 
24 
     | 
    
         
             
                    begin
         
     | 
| 
       22 
     | 
    
         
            -
                      self[field_name 
     | 
| 
      
 25 
     | 
    
         
            +
                      self[field_name].fetch(locale.to_s)
         
     | 
| 
       23 
26 
     | 
    
         
             
                    rescue IndexError
         
     | 
| 
       24 
27 
     | 
    
         
             
                      raise ArgumentError, "Invalid locale #{locale}" unless I18n.available_locales.include?(locale.to_sym)
         
     | 
| 
       25 
28 
     | 
    
         
             
                      nil
         
     | 
    
        data/lib/tolken/version.rb
    CHANGED
    
    
    
        data/tolken.gemspec
    CHANGED
    
    | 
         @@ -7,8 +7,8 @@ require "tolken/version" 
     | 
|
| 
       7 
7 
     | 
    
         
             
            Gem::Specification.new do |spec|
         
     | 
| 
       8 
8 
     | 
    
         
             
              spec.name          = "tolken"
         
     | 
| 
       9 
9 
     | 
    
         
             
              spec.version       = Tolken::VERSION
         
     | 
| 
       10 
     | 
    
         
            -
              spec.authors       = ["Nicklas Ramhöj, Julia  
     | 
| 
       11 
     | 
    
         
            -
              spec.email         = ["nicklas.ramhoj@varvet.com, julia. 
     | 
| 
      
 10 
     | 
    
         
            +
              spec.authors       = ["Nicklas Ramhöj, Julia Friberg"]
         
     | 
| 
      
 11 
     | 
    
         
            +
              spec.email         = ["nicklas.ramhoj@varvet.com, julia.friberg@varvet.com"]
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              spec.summary       = "A down-to-earth database translation Gem for Rails using psql jsonb"
         
     | 
| 
       14 
14 
     | 
    
         
             
              spec.description   = """
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: tolken
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
     | 
    
         
            -
            - Nicklas Ramhöj, Julia  
     | 
| 
      
 7 
     | 
    
         
            +
            - Nicklas Ramhöj, Julia Friberg
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018-08- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-08-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -173,7 +173,7 @@ description: "\n    A down-to-earth database translation Gem for Rails using psq 
     | 
|
| 
       173 
173 
     | 
    
         
             
              a translatable field is just a Ruby hash which makes it easy to reason about.\n
         
     | 
| 
       174 
174 
     | 
    
         
             
              \ "
         
     | 
| 
       175 
175 
     | 
    
         
             
            email:
         
     | 
| 
       176 
     | 
    
         
            -
            - nicklas.ramhoj@varvet.com, julia. 
     | 
| 
      
 176 
     | 
    
         
            +
            - nicklas.ramhoj@varvet.com, julia.friberg@varvet.com
         
     | 
| 
       177 
177 
     | 
    
         
             
            executables: []
         
     | 
| 
       178 
178 
     | 
    
         
             
            extensions: []
         
     | 
| 
       179 
179 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
         @@ -191,7 +191,7 @@ files: 
     | 
|
| 
       191 
191 
     | 
    
         
             
            - bin/setup
         
     | 
| 
       192 
192 
     | 
    
         
             
            - lib/tolken.rb
         
     | 
| 
       193 
193 
     | 
    
         
             
            - lib/tolken/hash_serializer.rb
         
     | 
| 
       194 
     | 
    
         
            -
            - lib/tolken/ 
     | 
| 
      
 194 
     | 
    
         
            +
            - lib/tolken/simple_form.rb
         
     | 
| 
       195 
195 
     | 
    
         
             
            - lib/tolken/translates.rb
         
     | 
| 
       196 
196 
     | 
    
         
             
            - lib/tolken/version.rb
         
     | 
| 
       197 
197 
     | 
    
         
             
            - tolken.gemspec
         
     |