Skip to content

Commit

Permalink
complete ember-intl upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Yibaebi committed Dec 6, 2024
1 parent f1343f9 commit d56fb0c
Show file tree
Hide file tree
Showing 208 changed files with 1,452 additions and 941 deletions.
45 changes: 35 additions & 10 deletions app/components/account-settings/general/select-language/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';
import IntlService from 'ember-intl/services/intl';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import type IntlService from 'ember-intl/services/intl';
import type Store from '@ember-data/store';

import ENV from 'irene/config/environment';
import DatetimeService from 'irene/services/datetime';
import parseError from 'irene/utils/parse-error';
import type DatetimeService from 'irene/services/datetime';

const localeStrings = {
en: 'English',
Expand All @@ -18,12 +21,20 @@ export default class AccountSettingsGeneralSelectLanguageComponent extends Compo
@service declare intl: IntlService;
@service declare ajax: any;
@service declare datetime: DatetimeService;
@service declare session: any;
@service declare store: Store;
@service('notifications') declare notify: NotificationService;

@tracked userLangPref = 'en';

constructor(owner: unknown, args: object) {
super(owner, args);

this.getUserLangPref.perform();
}

get currentLocale() {
return this.allLocales.find(
({ locale }) => locale === this.intl.locale.toString()
);
return this.allLocales.find(({ locale }) => locale === this.userLangPref);
}

get allLocales() {
Expand All @@ -35,10 +46,17 @@ export default class AccountSettingsGeneralSelectLanguageComponent extends Compo
.filter((f) => Boolean(f.localeString));
}

@action
handleLocaleChange(selection: { locale: string; localeString: string }) {
this.setLocale.perform(selection);
}

setLocale = task(async (selection) => {
const lang = selection.locale;

this.intl.locale = lang;
this.userLangPref = lang;

this.intl.setLocale(lang);

this.datetime.setLocale(lang);

Expand All @@ -58,10 +76,17 @@ export default class AccountSettingsGeneralSelectLanguageComponent extends Compo
}
});

@action
handleLocaleChange(selection: { locale: string; localeString: string }) {
this.setLocale.perform(selection);
}
getUserLangPref = task(async () => {
try {
const userId = this.session.data.authenticated.user_id;

const user = await this.store.findRecord('user', userId);

this.userLangPref = user.lang;
} catch (err) {
this.notify.error(parseError(err));
}
});
}

declare module '@glint/environment-ember-loose/registry' {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<div>
<div data-test-nf-newversn-primary-message>
{{t
'notificationModule.messages.nf-am-newversn'
platform_display=@context.platform_display
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span>
<span data-test-nf-nsapprvd1-primary-message>
{{t
'notificationModule.messages.nf-nsapprvd1'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<div>
<div data-test-nf-nsapprvd2-primary-message>
{{t
'notificationModule.messages.nf-nsapprvd2'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div data-test-nf-nsautoapprvd1-primary-message>
{{t
'notificationModule.messages.nf-nsautoapprvd1'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div data-test-nf-nsautoapprvd2-primary-message>
{{t
'notificationModule.messages.nf-nsautoapprvd2'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div data-test-nf-nsrejctd1-primary-message>
{{t
'notificationModule.messages.nf-nsrejctd1'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div data-test-nf-nfUpldfailnprjdeny1-primary-message>
{{t
'notificationModule.messages.nf-upldfailnprjdeny1'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div data-test-nf-upldfailnscreatd1-primary-message>
{{t
'notificationModule.messages.nf-upldfailnscreatd1'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
<div data-test-nf-upldfailnsunaprv1-primary-message>
{{t
'notificationModule.messages.nf-upldfailnsunaprv1'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span>
<span data-test-nf-upldfailpay2-primary-message>
{{t
'notificationModule.messages.nf-upldfailpay2'
htmlSafe=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span>
<span data-test-nf-upldfailpayrq1-primary-message>
{{t
'notificationModule.messages.nf-upldfailpayrq1'
htmlSafe=true
Expand Down
Loading

0 comments on commit d56fb0c

Please sign in to comment.