fnando / i18n-js

It's a small library to provide the I18n translations on the Javascript. It comes with Rails support.
MIT License
3.75k stars 519 forks source link

Bug: I18n.t is not a function & I18n is not defined #674

Closed chinhnguyen93 closed 1 year ago

chinhnguyen93 commented 1 year ago

Description

I face two issues when use this gem in Rails app (Rails 5.0, ruby 2.7.6) as below: I18n.t is not a function in coffee script file I18n is not defined in html slim file

Gemfile: gem 'i18n-js' Gemfile.lock i18n-js (4.0.1) config/i18n.yml

translations:
  - file: "app/assets/javascripts/i18n/%{locale}.js"
    patterns:
      - "*"
      - "!*.activerecord"
      - "!*.errors"
      - "!*.number.nth"

coffee script: I18n.t("javascripts.instance.xxx") -> this raise error: I18n.t is not a function

HTML:

javascript:
  I18n.defaultLocale = "#{I18n.default_locale}";
  I18n.locale = "#{I18n.locale}";

this raise error: I18n is not defined

fnando commented 1 year ago

Please follow the migration guide from v3 to v4. https://github.com/fnando/i18n-js/blob/main/MIGRATING_FROM_V3_TO_V4.md