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

fix(locales): make moment follow the locale set in the config #680

Merged
merged 2 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"lint-staged": "^10.5.4",
"print-message": "^3.0.1",
"rollup": "^2.39.0",
"rollup-plugin-copy-merge": "^0.2.0",
"rollup-plugin-cpy": "^2.0.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-emit-ejs": "^3.1.0",
Expand Down
13 changes: 12 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import packageJson from './package.json';
import progress from 'rollup-plugin-progress';
import mergeCopy from 'rollup-plugin-copy-merge';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-cpy';
Expand Down Expand Up @@ -99,8 +100,18 @@ const config = {
{ files: './favicon.png', dest: `./${outDir}/` },
{ files: './manifest.webmanifest', dest: `./${outDir}/` },
{ files: './images/*.*', dest: `./${outDir}/images/` },
{ files: `./node_modules/angular-i18n/angular-locale_(${BUNDLED_LOCALES.join('|')}).js`, dest: `./${outDir}/locales/` },
]),
mergeCopy({
targets: BUNDLED_LOCALES.map(locale => {
return {
src: [
`./node_modules/angular-i18n/angular-locale_${locale}.js`,
`./node_modules/moment/locale/${locale}.js`,
],
file: `./${outDir}/locales/${locale}.js`,
};
}),
}),
...appPlugins,
],
};
Expand Down
13 changes: 9 additions & 4 deletions scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ import { TYPES, FEATURES, HEADER_ITEMS, MENU_POSITIONS, CUSTOM_THEMES, GROUP_ALI
import { debounce, leadZero, supportsFeature, toAbsoluteServerURL } from '../globals/utils';
import Noty from '../models/noty';

App.controller('Main', function ($scope, $timeout, $location, Api, tmhDynamicLocale, $filter) {
App.controller('Main', function ($scope, $timeout, $location, Api, tmhDynamicLocale, $filter, amMoment) {
if (!window.CONFIG) {
return;
}

const CONFIG = window.CONFIG;

const locale = (CONFIG.locale || 'en-us').toLowerCase();
tmhDynamicLocale.set(locale).catch(() => {
Noty.add(Noty.ERROR, 'Failed loading locale', `Could not find corresponding file for locale "${locale}" in the /locales/ directory.`);
});
tmhDynamicLocale
.set(locale)
.catch(() => {
Noty.add(Noty.ERROR, 'Failed loading locale', `Could not find corresponding file for locale "${locale}" in the /locales/ directory.`);
})
.then(() => {
amMoment.changeLocale(locale);
});

if (CONFIG.groupsAlign === GROUP_ALIGNS.GRID && [CUSTOM_THEMES.MOBILE, CUSTOM_THEMES.WINPHONE].includes(CONFIG.customTheme)) {
CONFIG.groupsAlign = GROUP_ALIGNS.HORIZONTALLY;
Expand Down
2 changes: 2 additions & 0 deletions scripts/globals/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import angular from 'angular';
import moment from 'moment';

export { moment };

export const mergeObjects = angular.merge;

export const leadZero = function (num) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ window.initApp = function () {
authToken: window.CONFIG.authToken,
});

tmhDynamicLocaleProvider.localeLocationPattern('./locales/angular-locale_{{locale}}.js');
tmhDynamicLocaleProvider.localeLocationPattern('./locales/{{locale}}.js');

const clock24 = window.CONFIG.timeFormat === 24;

Expand Down
39 changes: 38 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,13 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==

"@types/fs-extra@^8.0.1":
version "8.1.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.1.tgz#1e49f22d09aa46e19b51c0b013cb63d0d923a068"
integrity sha512-TcUlBem321DFQzBNuz8p0CLLKp0VvF/XH9E4KHNmgwyp4E3AfgI5cjiIVZWlbfThBop2qxFIh4+LeY6hVWWZ2w==
dependencies:
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
Expand Down Expand Up @@ -1747,7 +1754,7 @@ color@^3.0.0:
color-convert "^1.9.1"
color-string "^1.5.4"

colorette@^1.2.1, colorette@^1.2.2:
colorette@^1.1.0, colorette@^1.2.1, colorette@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94"
integrity sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==
Expand Down Expand Up @@ -3111,6 +3118,20 @@ globals@^13.6.0:
dependencies:
type-fest "^0.20.2"

globby@10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22"
integrity sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==
dependencies:
"@types/glob" "^7.1.1"
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.0.3"
glob "^7.1.3"
ignore "^5.1.1"
merge2 "^1.2.3"
slash "^3.0.0"

globby@^10.0.1:
version "10.0.2"
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.2.tgz#277593e745acaa4646c3ab411289ec47a0392543"
Expand Down Expand Up @@ -3658,6 +3679,11 @@ is-plain-object@^2.0.3, is-plain-object@^2.0.4:
dependencies:
isobject "^3.0.1"

is-plain-object@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-3.0.1.tgz#662d92d24c0aa4302407b0d45d21f2251c85f85b"
integrity sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==

is-reference@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7"
Expand Down Expand Up @@ -5580,6 +5606,17 @@ rimraf@^3.0.0, rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rollup-plugin-copy-merge@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-copy-merge/-/rollup-plugin-copy-merge-0.2.0.tgz#08d1d4ff41062d1a9a2dd1d155dfc880a6ec0afc"
integrity sha512-WEwJY46/tm+ziMy/fucXYproUePKDLk3rA1t5IKX7cu+wfXQb1afE1T3s4p3lNBo6O7xD0z6DuN84ui30RqfMQ==
dependencies:
"@types/fs-extra" "^8.0.1"
colorette "^1.1.0"
fs-extra "^8.1.0"
globby "10.0.1"
is-plain-object "^3.0.0"

rollup-plugin-cpy@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-cpy/-/rollup-plugin-cpy-2.0.1.tgz#535be0abbd49397268a87bf1926d84cf988b728f"
Expand Down