isomorfeus-i18n 2.0.20 → 2.1.1
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/README.md +65 -5
- data/lib/isomorfeus/i18n/config.rb +20 -14
- data/lib/isomorfeus/i18n/handler/locale_handler.rb +9 -3
- data/lib/isomorfeus/i18n/init.rb +7 -4
- data/lib/isomorfeus/i18n/middleware.rb +19 -0
- data/lib/isomorfeus/i18n/reducer.rb +1 -1
- data/lib/isomorfeus/i18n/version.rb +1 -1
- data/lib/isomorfeus-i18n.rb +7 -4
- data/lib/{lucid_translation → lucid_i18n}/mixin.rb +86 -9
- metadata +23 -21
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cee15c2f1a1c0d49c08edbbd48b1cfbcbe5e3af1adecf3589abc57b4c0164da9
         | 
| 4 | 
            +
              data.tar.gz: d0003d85f7345e223b1a41917ac184dd7f12ae8b3e0df5265a976b3e57b0360c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d47c81d0b9289ddfc0542d1f5d4f2ed98937a9bb3b6543a1c4b47ee33b7bb80f6436c639533695f5fc126a50a893f3142331f1390652882173e4e5e764850317
         | 
| 7 | 
            +
              data.tar.gz: d0805720679d7042464d72f9f4a77284d3883060870f822ee80702fe2d15cb6b18687817cb4a0add376bcedddcbd60d662701e8afb323256543813413ba3aa6f
         | 
    
        data/README.md
    CHANGED
    
    | @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            Internationalization for Isomorfeus.
         | 
| 4 4 |  | 
| 5 5 | 
             
            ### Community and Support
         | 
| 6 | 
            -
            At the [Isomorfeus Framework Project]( | 
| 6 | 
            +
            At the [Isomorfeus Framework Project](https://isomorfeus.com)
         | 
| 7 7 |  | 
| 8 8 | 
             
            ### Usage
         | 
| 9 9 | 
             
            Locale files go in my_app/isomorfeus/locales.
         | 
| @@ -11,12 +11,72 @@ Supported formats: .mo, .po, .yml | |
| 11 11 |  | 
| 12 12 | 
             
            Using fast_gettext internally.
         | 
| 13 13 |  | 
| 14 | 
            -
            ##  | 
| 14 | 
            +
            ## Translation
         | 
| 15 15 |  | 
| 16 16 | 
             
            In any class:
         | 
| 17 17 | 
             
            ```
         | 
| 18 | 
            -
              include  | 
| 18 | 
            +
              include LucidI18n::Mixin
         | 
| 19 19 | 
             
            ```
         | 
| 20 | 
            -
             | 
| 21 20 | 
             
            after which the _ gettext methods are available for translation.
         | 
| 22 | 
            -
            See https://github.com/grosser/fast_gettext  | 
| 21 | 
            +
            See the [fast_gettext documentation](https://github.com/grosser/fast_gettext) or the
         | 
| 22 | 
            +
            [gettext documentation](https://rubydoc.info/gems/gettext/).
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            Also available is the `current_locale` helper, which provides the current locale as string, as it has been negotiated between browser and server.
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            ## Localization
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            In any class:
         | 
| 29 | 
            +
            ```
         | 
| 30 | 
            +
              include LucidI18n::Mixin
         | 
| 31 | 
            +
            ```
         | 
| 32 | 
            +
            after which the l method is available, which currently can localize Times, Dates and numbers.
         | 
| 33 | 
            +
            See the [R18n core documentation](https://github.com/r18n/r18n-core)
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Only the :full and :standard options are supported for the l method in all environments.
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            However, output may slightly differ between server and browser and also between browsers, depending on actual browser locale and implementation.
         | 
| 38 | 
            +
            For most consistent and best results its best to format dates and numbers for display only within components in server side rendering or in the browser.
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            Within components, the l method allows for additional options for Date and Time objects:
         | 
| 41 | 
            +
            ```ruby
         | 
| 42 | 
            +
            # signature
         | 
| 43 | 
            +
            l(object, format = :standard, options = {})
         | 
| 44 | 
            +
            ```
         | 
| 45 | 
            +
            Here format can be:
         | 
| 46 | 
            +
            - :standard or :full, which try to be consistent with r18n options
         | 
| 47 | 
            +
            and in addition:
         | 
| 48 | 
            +
            - :custom, which passes the options hash along for formatting to the browser or node functions.
         | 
| 49 | 
            +
            The following options are available for date/time formating:
         | 
| 50 | 
            +
            - locale: locale string like 'de'
         | 
| 51 | 
            +
            - time_zone or timeZone: timezone string like 'CET'
         | 
| 52 | 
            +
            - time_zone_name or timeZoneName: "long" "short"
         | 
| 53 | 
            +
            - date_style or dateStyle: "full" "long" "medium" "short"
         | 
| 54 | 
            +
            - time_style or timeStyle: "full" "long" "medium" "short"
         | 
| 55 | 
            +
            - format_matcher or formatMatcher: "best-fit"(default) "basic"
         | 
| 56 | 
            +
            - locale_matcher or localeMatcher: "best-fit"(default) "lookup"
         | 
| 57 | 
            +
            - hour12: false true
         | 
| 58 | 
            +
            - hour_cycle hourCycle: "h11" "h12" "h23" "h24"
         | 
| 59 | 
            +
            - hour:	   "2-digit" "numeric"
         | 
| 60 | 
            +
            - minute:	 "2-digit" "numeric"
         | 
| 61 | 
            +
            - second:	 "2-digit" "numeric"
         | 
| 62 | 
            +
            - day	     "2-digit" "numeric"
         | 
| 63 | 
            +
            - month:   "2-digit" "numeric" "long" "short" "narrow"
         | 
| 64 | 
            +
            - weekday:                     "long" "short" "narrow"
         | 
| 65 | 
            +
            - year:	   "2-digit" "numeric"
         | 
| 66 | 
            +
            For formatting numbers the options are available:
         | 
| 67 | 
            +
            - currency: any currency code (like "EUR", "USD", "INR", etc.)
         | 
| 68 | 
            +
            - currency_display or currencyDisplay: "symbol"(default) "code" "name"
         | 
| 69 | 
            +
            - locale_matcher or localeMatcher: "best-fit"(default) "lookup"
         | 
| 70 | 
            +
            - maximum_fraction_digits or maximumFractionDigits: A number from 0 to 20 (default is 3)
         | 
| 71 | 
            +
            - maximum_significant_digits or maximumSignificantDigits: A number from 1 to 21 (default is 21)
         | 
| 72 | 
            +
            - minimum_fraction_digits or minimumFractionDigits: A number from 0 to 20 (default is 3)
         | 
| 73 | 
            +
            - minimum_integer_digits or minimumIntegerDigits:	A number from 1 to 21 (default is 1)
         | 
| 74 | 
            +
            - minimum_significant_digits or minimumSignificantDigits:	A number from 1 to 21 (default is 21)
         | 
| 75 | 
            +
            - style: "decimal"(default) "currency" "percent"
         | 
| 76 | 
            +
            - use_grouping or useGrouping: true(default) false
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            example:
         | 
| 79 | 
            +
            ```ruby
         | 
| 80 | 
            +
            l(Time.now, :custom, { hour12: true })
         | 
| 81 | 
            +
            l(1.2345, :custom, { maximum_fraction_digits: 2 })
         | 
| 82 | 
            +
            ```
         | 
| @@ -19,24 +19,18 @@ module Isomorfeus | |
| 19 19 | 
             
                    domain
         | 
| 20 20 | 
             
                  end
         | 
| 21 21 |  | 
| 22 | 
            -
                  def  | 
| 22 | 
            +
                  def default_locale
         | 
| 23 23 | 
             
                    result = Redux.fetch_by_path(:i18n_state, :locale)
         | 
| 24 24 | 
             
                    result ? result : available_locales.first
         | 
| 25 25 | 
             
                  end
         | 
| 26 26 |  | 
| 27 | 
            -
                  def  | 
| 27 | 
            +
                  def default_locale=(loc)
         | 
| 28 28 | 
             
                    Isomorfeus.raise_error(message: "Locale #{loc} not available!") unless available_locales.include?(loc)
         | 
| 29 | 
            -
                    Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { locale:  | 
| 29 | 
            +
                    Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: { locale: loc })
         | 
| 30 30 | 
             
                    loc
         | 
| 31 31 | 
             
                  end
         | 
| 32 32 |  | 
| 33 | 
            -
                   | 
| 34 | 
            -
                    @negotiated_locale
         | 
| 35 | 
            -
                  end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                  def negotiated_locale=(l)
         | 
| 38 | 
            -
                    @negotiated_locale = l
         | 
| 39 | 
            -
                  end
         | 
| 33 | 
            +
                  attr_accessor :current_locale
         | 
| 40 34 | 
             
                else
         | 
| 41 35 | 
             
                  def available_locales
         | 
| 42 36 | 
             
                    @available_locales
         | 
| @@ -56,14 +50,26 @@ module Isomorfeus | |
| 56 50 | 
             
                    @i18n_domain = domain
         | 
| 57 51 | 
             
                  end
         | 
| 58 52 |  | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def current_locale
         | 
| 55 | 
            +
                    Thread.current[:isomorfeus_locale]
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def current_locale=(loc)
         | 
| 59 | 
            +
                    FastGettext.locale = loc
         | 
| 60 | 
            +
                    R18n.thread_set(loc)
         | 
| 61 | 
            +
                    Thread.current[:isomorfeus_locale] = loc
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def default_locale
         | 
| 65 | 
            +
                    @default_locale
         | 
| 61 66 | 
             
                  end
         | 
| 62 67 |  | 
| 63 | 
            -
                  def  | 
| 68 | 
            +
                  def default_locale=(loc)
         | 
| 64 69 | 
             
                    Isomorfeus.raise_error(message: "Locale #{loc} not available!") unless available_locales.include?(loc)
         | 
| 65 70 | 
             
                    FastGettext.locale = loc
         | 
| 66 | 
            -
                     | 
| 71 | 
            +
                    R18n.set(loc)
         | 
| 72 | 
            +
                    @default_locale = loc
         | 
| 67 73 | 
             
                  end
         | 
| 68 74 |  | 
| 69 75 | 
             
                  def locale_path
         | 
| @@ -17,9 +17,9 @@ module Isomorfeus | |
| 17 17 | 
             
                          response_agent.agent_result['data'] = { 'available_locales' => FastGettext.available_locales,
         | 
| 18 18 | 
             
                                                                  'domain' => FastGettext.text_domain }
         | 
| 19 19 | 
             
                          response_agent.agent_result['data']['locale'] = if Isomorfeus.available_locales.include?(locale)
         | 
| 20 | 
            -
                                                                            locale
         | 
| 20 | 
            +
                                                                            Isomorfeus.current_locale = locale
         | 
| 21 21 | 
             
                                                                          else
         | 
| 22 | 
            -
                                                                             | 
| 22 | 
            +
                                                                            Isomorfeus.current_locale = Isomorfeus.default_locale
         | 
| 23 23 | 
             
                                                                          end
         | 
| 24 24 | 
             
                        else
         | 
| 25 25 | 
             
                          response_agent.agent_result[domain] = {}
         | 
| @@ -31,7 +31,13 @@ module Isomorfeus | |
| 31 31 | 
             
                            FastGettext.with_domain(domain) do
         | 
| 32 32 | 
             
                              response_agent.request[domain].each_key do |locale|
         | 
| 33 33 | 
             
                                response_agent.agent_result[domain][locale] = {}
         | 
| 34 | 
            -
                                Isomorfeus. | 
| 34 | 
            +
                                if Isomorfeus.current_locale != locale
         | 
| 35 | 
            +
                                  if Isomorfeus.available_locales.include?(locale)
         | 
| 36 | 
            +
                                    Isomorfeus.current_locale = locale
         | 
| 37 | 
            +
                                  else
         | 
| 38 | 
            +
                                    Isomorfeus.raise_error(message: "Locale #{locale} not available!")
         | 
| 39 | 
            +
                                  end
         | 
| 40 | 
            +
                                end
         | 
| 35 41 | 
             
                                FastGettext.with_locale(locale) do
         | 
| 36 42 | 
             
                                  response_agent.request[domain][locale].each_key do |locale_method|
         | 
| 37 43 | 
             
                                    method_args = response_agent.request[domain][locale][locale_method]
         | 
    
        data/lib/isomorfeus/i18n/init.rb
    CHANGED
    
    | @@ -11,13 +11,17 @@ module Isomorfeus | |
| 11 11 | 
             
                        @initialized = false
         | 
| 12 12 | 
             
                        if Isomorfeus.on_browser?
         | 
| 13 13 | 
             
                          root_element = `document.querySelector('div[data-iso-root]')`
         | 
| 14 | 
            -
                           | 
| 14 | 
            +
                          if root_element
         | 
| 15 | 
            +
                            Isomorfeus.current_locale = root_element.JS.getAttribute('data-iso-nloc')
         | 
| 16 | 
            +
                          else
         | 
| 17 | 
            +
                            Isomorfeus.current_locale = Isomorfeus.default_locale
         | 
| 18 | 
            +
                          end
         | 
| 15 19 | 
             
                        end
         | 
| 16 20 | 
             
                        self.init_promise = init_from_server
         | 
| 17 21 | 
             
                      end
         | 
| 18 22 |  | 
| 19 23 | 
             
                      def init_from_server
         | 
| 20 | 
            -
                        Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus. | 
| 24 | 
            +
                        Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.current_locale).then do |agent|
         | 
| 21 25 | 
             
                          agent.process do
         | 
| 22 26 | 
             
                            @initializing = false
         | 
| 23 27 | 
             
                            Isomorfeus.store.dispatch(type: 'I18N_LOAD', data: agent.response[:data])
         | 
| @@ -27,7 +31,7 @@ module Isomorfeus | |
| 27 31 | 
             
                      end
         | 
| 28 32 |  | 
| 29 33 | 
             
                      def reload_from_server
         | 
| 30 | 
            -
                        Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus. | 
| 34 | 
            +
                        Isomorfeus::Transport.promise_send_path('Isomorfeus::I18n::Handler::LocaleHandler', :init, Isomorfeus.current_locale).then do |agent|
         | 
| 31 35 | 
             
                          agent.process do
         | 
| 32 36 | 
             
                            Isomorfeus.store.dispatch(type: 'I18N_STATE', set_state: agent.response[:data])
         | 
| 33 37 | 
             
                          end
         | 
| @@ -42,7 +46,6 @@ module Isomorfeus | |
| 42 46 | 
             
                        FastGettext.add_text_domain(Isomorfeus.i18n_domain, path: Isomorfeus.locale_path, type: Isomorfeus.i18n_type)
         | 
| 43 47 | 
             
                        FastGettext.available_locales = Isomorfeus.available_locales
         | 
| 44 48 | 
             
                        FastGettext.text_domain = Isomorfeus.i18n_domain
         | 
| 45 | 
            -
                        FastGettext.locale = Isomorfeus.locale
         | 
| 46 49 | 
             
                        Thread.current[:isomorfeus_i18n_initialized] = true
         | 
| 47 50 | 
             
                      end
         | 
| 48 51 | 
             
                    end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Isomorfeus
         | 
| 4 | 
            +
              module I18n
         | 
| 5 | 
            +
                class Middleware
         | 
| 6 | 
            +
                  def initialize(app)
         | 
| 7 | 
            +
                    @app = app
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def call(env)
         | 
| 11 | 
            +
                    locale = env.http_accept_language.preferred_language_from(Isomorfeus.available_locales) ||
         | 
| 12 | 
            +
                               env.http_accept_language.compatible_language_from(Isomorfeus.available_locales) ||
         | 
| 13 | 
            +
                               Isomorfeus.default_locale
         | 
| 14 | 
            +
                    Isomorfeus.current_locale = locale if Isomorfeus.current_locale != locale
         | 
| 15 | 
            +
                    @app.call(env)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/isomorfeus-i18n.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ if RUBY_ENGINE == 'opal' | |
| 4 4 | 
             
              require 'isomorfeus/i18n/config'
         | 
| 5 5 | 
             
              require 'isomorfeus/i18n/reducer'
         | 
| 6 6 | 
             
              Isomorfeus::I18n::Reducer.add_reducer_to_store
         | 
| 7 | 
            -
              require ' | 
| 7 | 
            +
              require 'lucid_i18n/mixin'
         | 
| 8 8 | 
             
              require 'isomorfeus/i18n/init'
         | 
| 9 9 | 
             
              if Isomorfeus.on_browser?
         | 
| 10 10 | 
             
                Isomorfeus.add_client_init_after_store_class_name('Isomorfeus::I18n::Init')
         | 
| @@ -14,6 +14,7 @@ if RUBY_ENGINE == 'opal' | |
| 14 14 | 
             
            else
         | 
| 15 15 | 
             
              require 'active_support'
         | 
| 16 16 | 
             
              require 'oj'
         | 
| 17 | 
            +
              require 'r18n-core'
         | 
| 17 18 | 
             
              require 'fast_gettext'
         | 
| 18 19 | 
             
              require 'isomorfeus/fast_gettext_cache'
         | 
| 19 20 | 
             
              require 'http_accept_language/parser'
         | 
| @@ -21,10 +22,12 @@ else | |
| 21 22 | 
             
              require 'isomorfeus-data'
         | 
| 22 23 | 
             
              require 'isomorfeus/i18n/config'
         | 
| 23 24 | 
             
              require 'isomorfeus/i18n/init'
         | 
| 24 | 
            -
              require ' | 
| 25 | 
            +
              require 'lucid_i18n/mixin'
         | 
| 25 26 | 
             
              require 'isomorfeus/i18n/handler/locale_handler'
         | 
| 27 | 
            +
              require 'isomorfeus/i18n/middleware'
         | 
| 26 28 |  | 
| 27 29 | 
             
              Isomorfeus.add_middleware(HttpAcceptLanguage::Middleware)
         | 
| 30 | 
            +
              Isomorfeus.insert_middleware_after(HttpAcceptLanguage::Middleware, Isomorfeus::I18n::Middleware)
         | 
| 28 31 |  | 
| 29 32 | 
             
              require 'iso_opal'
         | 
| 30 33 | 
             
              Opal.append_path(__dir__.untaint) unless IsoOpal.paths.include?(__dir__.untaint)
         | 
| @@ -62,9 +65,9 @@ else | |
| 62 65 | 
             
              Isomorfeus.available_locales = ['en'] if Isomorfeus.available_locales.empty?
         | 
| 63 66 |  | 
| 64 67 | 
             
              if Isomorfeus.available_locales.include?('en')
         | 
| 65 | 
            -
                Isomorfeus. | 
| 68 | 
            +
                Isomorfeus.default_locale = 'en'
         | 
| 66 69 | 
             
              else
         | 
| 67 | 
            -
                Isomorfeus. | 
| 70 | 
            +
                Isomorfeus.default_locale = Isomorfeus.available_locales.first
         | 
| 68 71 | 
             
              end
         | 
| 69 72 |  | 
| 70 73 | 
             
              Isomorfeus.i18n_domain = 'app'
         | 
| @@ -1,14 +1,18 @@ | |
| 1 | 
            -
            module  | 
| 1 | 
            +
            module LucidI18n
         | 
| 2 2 | 
             
              module Mixin
         | 
| 3 3 | 
             
                CONTEXT_SEPARATOR = "\004"
         | 
| 4 4 | 
             
                NAMESPACE_SEPARATOR = '|'
         | 
| 5 5 | 
             
                NIL_BLOCK = -> { nil }
         | 
| 6 6 | 
             
                TRANSLATION_METHODS = [:_, :n_, :np_, :ns_, :p_, :s_]
         | 
| 7 7 |  | 
| 8 | 
            +
                def current_locale
         | 
| 9 | 
            +
                  Isomorfeus.current_locale
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 8 12 | 
             
                if RUBY_ENGINE == 'opal'
         | 
| 9 13 | 
             
                  def _(*keys, &block)
         | 
| 10 14 | 
             
                    domain = Isomorfeus.i18n_domain
         | 
| 11 | 
            -
                    locale = Isomorfeus. | 
| 15 | 
            +
                    locale = Isomorfeus.current_locale
         | 
| 12 16 | 
             
                    Isomorfeus.raise_error(message: "I18n _(): no key given!") if keys.empty?
         | 
| 13 17 | 
             
                    result = Redux.fetch_by_path(:i18n_state, domain, locale, '_', keys)
         | 
| 14 18 | 
             
                    return result if result
         | 
| @@ -18,7 +22,7 @@ module LucidTranslation | |
| 18 22 |  | 
| 19 23 | 
             
                  def n_(*keys, count, &block)
         | 
| 20 24 | 
             
                    domain = Isomorfeus.i18n_domain
         | 
| 21 | 
            -
                    locale = Isomorfeus. | 
| 25 | 
            +
                    locale = Isomorfeus.current_locale
         | 
| 22 26 | 
             
                    Isomorfeus.raise_error(message: "I18n n_(): no key given!") if keys.empty?
         | 
| 23 27 | 
             
                    result = Redux.fetch_by_path(:i18n_state, domain, locale, 'n_', keys + [count])
         | 
| 24 28 | 
             
                    return result if result
         | 
| @@ -35,7 +39,7 @@ module LucidTranslation | |
| 35 39 |  | 
| 36 40 | 
             
                  def ns_(*args, &block)
         | 
| 37 41 | 
             
                    domain = Isomorfeus.i18n_domain
         | 
| 38 | 
            -
                    locale = Isomorfeus. | 
| 42 | 
            +
                    locale = Isomorfeus.current_locale
         | 
| 39 43 | 
             
                    Isomorfeus.raise_error(message: "I18n ns_(): no args given!") if args.empty?
         | 
| 40 44 | 
             
                    result = Redux.fetch_by_path(:i18n_state, domain, locale, 'ns_', args)
         | 
| 41 45 | 
             
                    return result if result
         | 
| @@ -45,7 +49,7 @@ module LucidTranslation | |
| 45 49 |  | 
| 46 50 | 
             
                  def p_(namespace, key, separator = nil, &block)
         | 
| 47 51 | 
             
                    domain = Isomorfeus.i18n_domain
         | 
| 48 | 
            -
                    locale = Isomorfeus. | 
| 52 | 
            +
                    locale = Isomorfeus.current_locale
         | 
| 49 53 | 
             
                    args = separator ? [namespace, key, separator] : [namespace, key]
         | 
| 50 54 | 
             
                    result = Redux.fetch_by_path(:i18n_state, domain, locale, 'p_', args)
         | 
| 51 55 | 
             
                    return result if result
         | 
| @@ -55,7 +59,7 @@ module LucidTranslation | |
| 55 59 |  | 
| 56 60 | 
             
                  def s_(key, separator = nil, &block)
         | 
| 57 61 | 
             
                    domain = Isomorfeus.i18n_domain
         | 
| 58 | 
            -
                    locale = Isomorfeus. | 
| 62 | 
            +
                    locale = Isomorfeus.current_locale
         | 
| 59 63 | 
             
                    args = separator ? [key, separator] : [key]
         | 
| 60 64 | 
             
                    result = Redux.fetch_by_path(:i18n_state, domain, locale, 's_', args)
         | 
| 61 65 | 
             
                    return result if result
         | 
| @@ -84,7 +88,7 @@ module LucidTranslation | |
| 84 88 |  | 
| 85 89 | 
             
                    define_method("D#{method}") do |*args, &block|
         | 
| 86 90 | 
             
                      domain = Isomorfeus.i18n_domain
         | 
| 87 | 
            -
                      locale = Isomorfeus. | 
| 91 | 
            +
                      locale = Isomorfeus.current_locale
         | 
| 88 92 | 
             
                      Isomorfeus.raise_error(message: "I18n D#{method}(): no args given!") if args.empty?
         | 
| 89 93 | 
             
                      result = Redux.fetch_by_path(:i18n_state, domain, locale, "D#{method}", args)
         | 
| 90 94 | 
             
                      return result if result
         | 
| @@ -93,6 +97,74 @@ module LucidTranslation | |
| 93 97 | 
             
                    end
         | 
| 94 98 | 
             
                  end
         | 
| 95 99 |  | 
| 100 | 
            +
                  def l(object, format = :standard, options = {})
         | 
| 101 | 
            +
                    c_name = object.class.to_s
         | 
| 102 | 
            +
                    locale = options.delete(:locale) { Isomorfeus.current_locale }
         | 
| 103 | 
            +
                    options = options.transform_keys { |k| `Opal.Preact.lower_camelize(k)` }
         | 
| 104 | 
            +
                    if object.is_a?(Numeric)
         | 
| 105 | 
            +
                      # options for number formatting:
         | 
| 106 | 
            +
                      # locale: locale string like 'de'
         | 
| 107 | 
            +
                      # currency: any currency code (like "EUR", "USD", "INR", etc.)
         | 
| 108 | 
            +
                      # currency_display or currencyDisplay: "symbol"(default) "code" "name"
         | 
| 109 | 
            +
                      # locale_matcher or localeMatcher: "best-fit"(default) "lookup"
         | 
| 110 | 
            +
                      # maximum_fraction_digits or maximumFractionDigits: A number from 0 to 20 (default is 3)
         | 
| 111 | 
            +
                      # maximum_significant_digits or maximumSignificantDigits: A number from 1 to 21 (default is 21)
         | 
| 112 | 
            +
                      # minimum_fraction_digits or minimumFractionDigits: A number from 0 to 20 (default is 3)
         | 
| 113 | 
            +
                      # minimum_integer_digits or minimumIntegerDigits:	A number from 1 to 21 (default is 1)
         | 
| 114 | 
            +
                      # minimum_significant_digits or minimumSignificantDigits:	A number from 1 to 21 (default is 21)
         | 
| 115 | 
            +
                      # style: "decimal"(default) "currency" "percent"
         | 
| 116 | 
            +
                      # use_grouping or useGrouping: true(default) false
         | 
| 117 | 
            +
                      `(object).toLocaleString(locale, #{options.to_n})`
         | 
| 118 | 
            +
                    elsif c_name == 'Date' || c_name == 'DateTime'
         | 
| 119 | 
            +
                      # options for date/time formating:
         | 
| 120 | 
            +
                      # format: "standard" "full"
         | 
| 121 | 
            +
                      # locale: locale string like 'de'
         | 
| 122 | 
            +
                      # time_zone or timeZone: timezone string like 'CET'
         | 
| 123 | 
            +
                      # time_zone_name or timeZoneName: "long" "short"
         | 
| 124 | 
            +
                      # date_style or dateStyle: "full" "long" "medium" "short"
         | 
| 125 | 
            +
                      # time_style or timeStyle: "full" "long" "medium" "short"
         | 
| 126 | 
            +
                      # format_matcher or formatMatcher: "best-fit"(default) "basic"
         | 
| 127 | 
            +
                      # locale_matcher or localeMatcher: "best-fit"(default) "lookup"
         | 
| 128 | 
            +
                      # hour12: false true
         | 
| 129 | 
            +
                      # hour_cycle hourCycle: "h11" "h12" "h23" "h24"
         | 
| 130 | 
            +
                      # hour:	   "2-digit" "numeric"
         | 
| 131 | 
            +
                      # minute:	 "2-digit" "numeric"
         | 
| 132 | 
            +
                      # second:	 "2-digit" "numeric"
         | 
| 133 | 
            +
                      # day	     "2-digit" "numeric"
         | 
| 134 | 
            +
                      # month:   "2-digit" "numeric" "long" "short" "narrow"
         | 
| 135 | 
            +
                      # weekday:                     "long" "short" "narrow"
         | 
| 136 | 
            +
                      # year:	   "2-digit" "numeric"
         | 
| 137 | 
            +
                      native_object = object.to_n
         | 
| 138 | 
            +
                      case format
         | 
| 139 | 
            +
                      when :standard
         | 
| 140 | 
            +
                        `native_object.toLocaleDateString(locale, #{options.to_n})`
         | 
| 141 | 
            +
                      when :full
         | 
| 142 | 
            +
                        options[:dateStyle] = 'long'
         | 
| 143 | 
            +
                        `native_object.toLocaleDateString(locale, #{options.to_n})`
         | 
| 144 | 
            +
                      when :custom
         | 
| 145 | 
            +
                        `native_object.toLocaleString(locale, #{options.to_n})`
         | 
| 146 | 
            +
                      else
         | 
| 147 | 
            +
                        `native_object.toLocaleDateString(locale, #{options.to_n})`
         | 
| 148 | 
            +
                      end
         | 
| 149 | 
            +
                    elsif c_name == 'Time'
         | 
| 150 | 
            +
                      native_object = object.to_n
         | 
| 151 | 
            +
                      case format
         | 
| 152 | 
            +
                      when :standard
         | 
| 153 | 
            +
                        `native_object.toLocaleString(locale, #{options.to_n})`
         | 
| 154 | 
            +
                      when :full
         | 
| 155 | 
            +
                        options[:dateStyle] = 'long'
         | 
| 156 | 
            +
                        options[:timeStyle] = 'short'
         | 
| 157 | 
            +
                        `native_object.toLocaleString(locale, #{options.to_n})`
         | 
| 158 | 
            +
                      when :custom
         | 
| 159 | 
            +
                        `native_object.toLocaleString(locale, #{options.to_n})`
         | 
| 160 | 
            +
                      else
         | 
| 161 | 
            +
                        `native_object.toLocaleString(locale, #{options.to_n})`
         | 
| 162 | 
            +
                      end
         | 
| 163 | 
            +
                    else
         | 
| 164 | 
            +
                      raise "Unknown object type #{object.class} given to #l!"
         | 
| 165 | 
            +
                    end
         | 
| 166 | 
            +
                  end
         | 
| 167 | 
            +
             | 
| 96 168 | 
             
                  private
         | 
| 97 169 |  | 
| 98 170 | 
             
                  def _promise_send_i18n_method(domain, locale, method, args)
         | 
| @@ -120,12 +192,17 @@ module LucidTranslation | |
| 120 192 | 
             
                      end
         | 
| 121 193 | 
             
                    end
         | 
| 122 194 | 
             
                  end
         | 
| 123 | 
            -
                else
         | 
| 195 | 
            +
                else # RUBY_ENGINE
         | 
| 124 196 | 
             
                  class InternalTranslationProxy
         | 
| 125 197 | 
             
                    extend FastGettext::Translation
         | 
| 126 198 | 
             
                    extend FastGettext::TranslationMultidomain
         | 
| 127 199 | 
             
                  end
         | 
| 128 200 |  | 
| 201 | 
            +
                  def l(object, format = :standard, _options = {})
         | 
| 202 | 
            +
                    Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
         | 
| 203 | 
            +
                    R18n.l(object, format)
         | 
| 204 | 
            +
                  end
         | 
| 205 | 
            +
             | 
| 129 206 | 
             
                  TRANSLATION_METHODS.each do |method|
         | 
| 130 207 | 
             
                    define_method(method) do |domain, *args, &block|
         | 
| 131 208 | 
             
                      Isomorfeus::I18n::Init.init unless Thread.current[:isomorfeus_i18n_initialized] == true
         | 
| @@ -142,6 +219,6 @@ module LucidTranslation | |
| 142 219 | 
             
                      InternalTranslationProxy.send("D#{method}", *args, &block)
         | 
| 143 220 | 
             
                    end
         | 
| 144 221 | 
             
                  end
         | 
| 145 | 
            -
                end
         | 
| 222 | 
            +
                end # RUBY_ENGINE
         | 
| 146 223 | 
             
              end
         | 
| 147 224 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: isomorfeus-i18n
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jan Biedermann
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-02- | 
| 11 | 
            +
            date: 2022-02-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -16,14 +16,14 @@ dependencies: | |
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: 7.0. | 
| 19 | 
            +
                    version: 7.0.2
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 24 | 
             
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: 7.0. | 
| 26 | 
            +
                    version: 7.0.2
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: fast_gettext
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -100,84 +100,84 @@ dependencies: | |
| 100 100 | 
             
                requirements:
         | 
| 101 101 | 
             
                - - "~>"
         | 
| 102 102 | 
             
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            -
                    version: 0.14. | 
| 103 | 
            +
                    version: 0.14.12
         | 
| 104 104 | 
             
              type: :runtime
         | 
| 105 105 | 
             
              prerelease: false
         | 
| 106 106 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 107 | 
             
                requirements:
         | 
| 108 108 | 
             
                - - "~>"
         | 
| 109 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            -
                    version: 0.14. | 
| 110 | 
            +
                    version: 0.14.12
         | 
| 111 111 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 112 112 | 
             
              name: isomorfeus-preact
         | 
| 113 113 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 114 | 
             
                requirements:
         | 
| 115 115 | 
             
                - - "~>"
         | 
| 116 116 | 
             
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            -
                    version: 10.6. | 
| 117 | 
            +
                    version: 10.6.36
         | 
| 118 118 | 
             
              type: :runtime
         | 
| 119 119 | 
             
              prerelease: false
         | 
| 120 120 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 121 | 
             
                requirements:
         | 
| 122 122 | 
             
                - - "~>"
         | 
| 123 123 | 
             
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            -
                    version: 10.6. | 
| 124 | 
            +
                    version: 10.6.36
         | 
| 125 125 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 126 126 | 
             
              name: isomorfeus-redux
         | 
| 127 127 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 128 | 
             
                requirements:
         | 
| 129 129 | 
             
                - - "~>"
         | 
| 130 130 | 
             
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            -
                    version: 4.1. | 
| 131 | 
            +
                    version: 4.1.17
         | 
| 132 132 | 
             
              type: :runtime
         | 
| 133 133 | 
             
              prerelease: false
         | 
| 134 134 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 135 | 
             
                requirements:
         | 
| 136 136 | 
             
                - - "~>"
         | 
| 137 137 | 
             
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            -
                    version: 4.1. | 
| 138 | 
            +
                    version: 4.1.17
         | 
| 139 139 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 140 140 | 
             
              name: isomorfeus-transport
         | 
| 141 141 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 142 | 
             
                requirements:
         | 
| 143 143 | 
             
                - - '='
         | 
| 144 144 | 
             
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            -
                    version: 2. | 
| 145 | 
            +
                    version: 2.1.1
         | 
| 146 146 | 
             
              type: :runtime
         | 
| 147 147 | 
             
              prerelease: false
         | 
| 148 148 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 149 | 
             
                requirements:
         | 
| 150 150 | 
             
                - - '='
         | 
| 151 151 | 
             
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            -
                    version: 2. | 
| 152 | 
            +
                    version: 2.1.1
         | 
| 153 153 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 154 | 
            -
              name:  | 
| 154 | 
            +
              name: r18n-core
         | 
| 155 155 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 156 156 | 
             
                requirements:
         | 
| 157 | 
            -
                - -  | 
| 157 | 
            +
                - - "~>"
         | 
| 158 158 | 
             
                  - !ruby/object:Gem::Version
         | 
| 159 | 
            -
                    version:  | 
| 159 | 
            +
                    version: 5.0.1
         | 
| 160 160 | 
             
              type: :runtime
         | 
| 161 161 | 
             
              prerelease: false
         | 
| 162 162 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 163 163 | 
             
                requirements:
         | 
| 164 | 
            -
                - -  | 
| 164 | 
            +
                - - "~>"
         | 
| 165 165 | 
             
                  - !ruby/object:Gem::Version
         | 
| 166 | 
            -
                    version:  | 
| 166 | 
            +
                    version: 5.0.1
         | 
| 167 167 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 168 168 | 
             
              name: isomorfeus
         | 
| 169 169 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 170 170 | 
             
                requirements:
         | 
| 171 171 | 
             
                - - '='
         | 
| 172 172 | 
             
                  - !ruby/object:Gem::Version
         | 
| 173 | 
            -
                    version: 2. | 
| 173 | 
            +
                    version: 2.1.1
         | 
| 174 174 | 
             
              type: :development
         | 
| 175 175 | 
             
              prerelease: false
         | 
| 176 176 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 177 177 | 
             
                requirements:
         | 
| 178 178 | 
             
                - - '='
         | 
| 179 179 | 
             
                  - !ruby/object:Gem::Version
         | 
| 180 | 
            -
                    version: 2. | 
| 180 | 
            +
                    version: 2.1.1
         | 
| 181 181 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 182 182 | 
             
              name: rake
         | 
| 183 183 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -219,14 +219,16 @@ files: | |
| 219 219 | 
             
            - lib/isomorfeus/i18n/config.rb
         | 
| 220 220 | 
             
            - lib/isomorfeus/i18n/handler/locale_handler.rb
         | 
| 221 221 | 
             
            - lib/isomorfeus/i18n/init.rb
         | 
| 222 | 
            +
            - lib/isomorfeus/i18n/middleware.rb
         | 
| 222 223 | 
             
            - lib/isomorfeus/i18n/reducer.rb
         | 
| 223 224 | 
             
            - lib/isomorfeus/i18n/version.rb
         | 
| 224 | 
            -
            - lib/ | 
| 225 | 
            -
            homepage:  | 
| 225 | 
            +
            - lib/lucid_i18n/mixin.rb
         | 
| 226 | 
            +
            homepage: https://isomorfeus.com
         | 
| 226 227 | 
             
            licenses:
         | 
| 227 228 | 
             
            - MIT
         | 
| 228 229 | 
             
            metadata:
         | 
| 229 230 | 
             
              github_repo: ssh://github.com/isomorfeus/gems
         | 
| 231 | 
            +
              source_code_uri: https://github.com/isomorfeus/isomorfeus-project/isomorfeus-i18n
         | 
| 230 232 | 
             
            post_install_message:
         | 
| 231 233 | 
             
            rdoc_options: []
         | 
| 232 234 | 
             
            require_paths:
         |