Skip to content

Commit

Permalink
I18n update (#862)
Browse files Browse the repository at this point in the history
* refactor(Meteor 3): 👽 Update i18n for meteor 3 api changes

* Revert change from map to foreach

* style: format code with clang-format

* style: format code with prettier

Signed-off-by: Ciarán <[email protected]>
Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
  • Loading branch information
bubonicfred and restyled-io[bot] authored Jun 16, 2024
1 parent 557ef5e commit 33239f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion imports/config/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AccountsTemplates } from "meteor/useraccounts:core";
const availLanguages = getLocaleCodes();

for (const lang of availLanguages) {
T9n.forEach(lang, {
T9n.map(lang, {
custom: {
usernamePlaceholder: i18n.__("Accounts.usernamePlaceholder", {
_locale: lang,
Expand Down
25 changes: 13 additions & 12 deletions imports/helpers/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ export class I18nHelper {
* returned.
* @returns {string} The language locale.
*/
static getLanguageLocale() {
static async getLanguageLocale() {
if (
!Meteor.user() ||
!Meteor.user().profile ||
!Meteor.user().profile.locale
!(await Meteor.userAsync()) ||
!(await Meteor.userAsync()).profile ||
!(await Meteor.userAsync()).profile.locale
) {
return "auto";
}
Expand All @@ -173,14 +173,14 @@ export class I18nHelper {
*
* @returns {string} The preferred user locale.
*/
static _getPreferredUserLocale() {
static async _getPreferredUserLocale() {
if (Meteor.settings?.public && Meteor.settings.public.isEnd2EndTest) {
return "en-US";
}
return (
(Meteor.user() &&
Meteor.user().profile &&
Meteor.user().profile.locale) ||
((await Meteor.userAsync()) &&
(await Meteor.userAsync()).profile &&
(await Meteor.userAsync()).profile.locale) ||
I18nHelper._getPreferredBrowserLocale()
);
}
Expand Down Expand Up @@ -256,17 +256,18 @@ export class I18nHelper {
* preference.
* @returns {void}
*/
static _persistLanguagePreference(localeCode) {
if (!Meteor.user() || Meteor.user().isDemoUser) {

static async _persistLanguagePreference(localeCode) {
if (!(await Meteor.userAsync()) || (await Meteor.userAsync()).isDemoUser) {
return;
}
if (localeCode === "auto") {
Meteor.users.update(
await Meteor.users.updateAsync(
{ _id: Meteor.userId() },
{ $unset: { "profile.locale": "" } },
);
} else {
Meteor.users.update(
await Meteor.users.updateAsync(
{ _id: Meteor.userId() },
{ $set: { "profile.locale": localeCode } },
);
Expand Down

0 comments on commit 33239f7

Please sign in to comment.