Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot format date. #8

Open
foton opened this issue Feb 13, 2020 · 0 comments
Open

Cannot format date. #8

foton opened this issue Feb 13, 2020 · 0 comments

Comments

@foton
Copy link

foton commented Feb 13, 2020

Hi,
I have trouble with localizing Time as date in view.

According https://github.com/TechMagister/i18n.cr
it can be done by scope like I18n.localize(Time.local, scope: :date, format: :long).

I set up default language in config/i18n.cr as

  settings.default_locale = "cs"

put into src/locales/cs.yml

---
tournament:
  one: Turnaj
  other: Turnaje

  # CS defaults grabbed from https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/cs.yml
__formats__:
  time:
    am: dopoledne
    pm: odpoledne
    formats:
      default: "%a %e. %B %Y %H:%M %z"
      long: "%A %e. %B %Y %H:%M"
      short: "%e. %-m. %H:%M"
  date:
    formats:
      default: "%d. %m. %Y"
      long: "%d. %B %Y"
      short: "%d %b"

and use l(Time.local, scope:date, format: :default). And compilation fails with

There was a problem expanding macro 'macro_139974350525760'

Code in macro 'embed'

 1 | {{ run("slang/slang/process", "src/views/tournament/index.slang", "__kilt_io__") }}
     ^
Called macro defined in macro 'embed'

 1 | {{ run("slang/slang/process", "src/views/tournament/index.slang", "__kilt_io__") }}

Which expanded to:

 > 177 | __kilt_io__ << "<td"
 > 178 | __kilt_io__ << ">"
 > 179 | __kilt_io__ << HTML.escape((l(Time.local, scope: :date, format: :default)).to_s).to_s(__kilt_io__)
                                     ^
Error: no argument named 'scope'

Matches are:
 - Amber::Controller::Helpers::I18n#l(*arg)

When i replace it with ::I18n.localize(Time.local, scope: :date, format: :default)
compilation is successful, but it uses locale "en" not "cs" (got [Missing translation : en#__formats__.date.formats.default] in view; and after filling it, correct "13. 02. 2020" is displayed).

When I use only l(Time.local), I got translated time in default format "Čt 13. únor 2020 08:56 +0100". Unfortunately using l(Time.local, format: :short) will end in same compilation error.

At same view file I have h2 = t("tournament.other") which IS translated into czech language nicely. (By the way t("tournament", count: 2) did not work either).

THE QUESTIONS:

  • How it can be done properly?
  • How can I get currently used locale in view ( ::I18n.config.locale => "en" ,Citrine::I18n.config.locale => compilation error`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant