Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
update format configuration when adding languages
Browse files Browse the repository at this point in the history
  • Loading branch information
atomfrede committed Oct 7, 2019
1 parent 985d9a0 commit cbdda6c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@ import * as filters from '@/shared/date/filters';

<%_ if (enableTranslation) { _%>
const dateTimeFormats = {
'default': {
short: {
year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric'
},
medium: {
year: 'numeric', month: 'short', day: 'numeric',
weekday: 'short', hour: 'numeric', minute: 'numeric'
},
long: {
year: 'numeric', month: 'long', day: 'numeric',
weekday: 'long', hour: 'numeric', minute: 'numeric'
}
},
// jhipster-needle-i18n-language-date-time-format - JHipster will add/remove format options in this object
'<%= nativeLanguage %>': {
short: {
year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric'
Expand Down
39 changes: 39 additions & 0 deletions generators/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ function updateLanguagesInConfig(generator) {
},
generator
);
// Add i18n config snippets for all languages
let i18nConfig = 'const dateTimeFormats = {\n';
i18nConfig += ' // jhipster-needle-i18n-language-date-time-format - JHipster will add/remove format options in this object\n';
if (generator.enableTranslation) {
generator.languages.forEach((ln, i) => {
i18nConfig += generateDateTimeFormat(ln, i, generator.languages.length);
});
}
i18nConfig += '}';
console.log(i18nConfig);
jhipsterUtils.replaceContent(
{
file: fullPath,
pattern: /const dateTimeFormats.*\{([^\]]*jhipster-needle-i18n-language-date-time-format[^}]*)}/g,
content: i18nConfig
},
generator
);
} catch (e) {
generator.log(
chalk.yellow('\nUnable to find ')
Expand All @@ -64,6 +82,27 @@ function updateLanguagesInConfig(generator) {
}
}

function generateDateTimeFormat(language, index, length) {
let config = ` '${language}': {\n`;

config += ' short: {\n';
config += ' year: \'numeric\', month: \'short\', day: \'numeric\', hour: \'numeric\', minute: \'numeric\'\n';
config += ' },\n';
config += ' medium: {\n';
config += ' year: \'numeric\', month: \'short\', day: \'numeric\',\n';
config += ' weekday: \'short\', hour: \'numeric\', minute: \'numeric\'\n';
config += ' },\n';
config += ' long: {\n';
config += ' year: \'numeric\', month: \'long\', day: \'numeric\',\n';
config += ' weekday: \'long\', hour: \'numeric\', minute: \'numeric\'\n';
config += ' }\n';
config += ' }';
if (index !== length - 1) {
config += ',';
}
config += '\n';
return config;
}
function updateLanguagesInWebpack(generator) {
const fullPath = `${CLIENT_WEBPACK_DIR}webpack.common.js`;
try {
Expand Down

0 comments on commit cbdda6c

Please sign in to comment.