Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Localize moment, timeAgo, ... #678

Closed
akloeckner opened this issue Mar 28, 2021 · 5 comments · Fixed by #680
Closed

Localize moment, timeAgo, ... #678

akloeckner opened this issue Mar 28, 2021 · 5 comments · Fixed by #680

Comments

@akloeckner
Copy link
Contributor

Now since there is an option locale, this option should also apply to usages of moment, for example in history graphs or in timeAgo. Because, now, locales are not 100% consistent.

However, I still don't have an idea, how to "properly" solve this. Apparently, we simply need to load the locale file, but I was advised against that, previously. Checking with angular's dynamic locale, they seem to do this, too. Just in a 3rd-party package.

@rchl
Copy link
Collaborator

rchl commented Mar 28, 2021

Yes, basically we've ended up with a solution that I was recommending against but hidden in a third-party code and slightly more robust.

And yes, we'd need to dynamically load the moment locale and then call amMoment.changeLocale(..).

I won't argue against it since it's apparently the only way to go if we don't want to include all locales in the bundle.

@akloeckner
Copy link
Contributor Author

Is there any “standard“ way to do this (load JS dynamically)?

I did some searching, but couldn't find a package or angular command to do it. Except jQuery, which might be overkill? I had a function to do it, basically copied from jQuery. But an externally maintained command might be favourable, I guess?

@rchl
Copy link
Collaborator

rchl commented Mar 28, 2021

https://www.npmjs.com/package/oclazyload looks pretty nice on first sight and has good documentation.

(Of course, as with most angularjs libraries, it's no longer maintained and has a lot of issues open but it might be just fine for our use case).

@akloeckner
Copy link
Contributor Author

akloeckner commented Mar 29, 2021

Or could we modify this line to merge (i.e. append) the contents of the moment locales into the file of the angular locales?

{ files: `./node_modules/angular-i18n/angular-locale_(${BUNDLED_LOCALES.join('|')}).js`, dest: `./${outDir}/locales/` },

That way we could rely on the single one mechanism (from dynamic angular locales) to load scripts dynamically. And we just needed to call amMoment.changeLocale when resolving this promise:

tmhDynamicLocale.set(locale).catch(() => {

@rchl
Copy link
Collaborator

rchl commented Mar 29, 2021

That sounded like a good idea. I've looked into it to see if that will work and ended up implementing it in #680.

alphasixtyfive pushed a commit that referenced this issue Mar 29, 2021
* fix(locales): make moment follow the locale set in the config

Resolves #678

* better order
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants