Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable ui-language-switcher-dialog.component.ts #2550

Merged
merged 15 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
e73dbf3
fix(admin-ui): Improve `stock-on-hand` translation
HoseinGhanbari Nov 27, 2023
6ac4cc8
fix(admin-ui): Fill `selectedCurrencyCode` & `currentLocale` based on…
HoseinGhanbari Nov 27, 2023
0a62e74
fix(admin-ui,admin-ui-plugin,common): Add configurable `availableLoca…
HoseinGhanbari Nov 27, 2023
47291d8
fix(admin-ui): Fix default values for `vendure-ui-config.json`
HoseinGhanbari Nov 27, 2023
381ddf2
fix(common): Add more precise @description & @since
HoseinGhanbari Nov 29, 2023
6bc6c27
fix(admin-ui): Add string type for `selectedCurrencyCode`
HoseinGhanbari Nov 29, 2023
6c81563
fix(admin-ui-plugin): Fix `[prop]` access check + Refactor final `pro…
HoseinGhanbari Nov 29, 2023
271312a
fix(admin-ui): Make `availableLocales` inside `vendure-ui-config.json…
HoseinGhanbari Nov 29, 2023
36a8c26
fix(admin-ui-plugin): Add defaultLocale value
HoseinGhanbari Nov 29, 2023
e389436
fix(admin-ui): Make `availableLanguages` & `availableLocales` pre-filled
HoseinGhanbari Nov 29, 2023
bf32a67
feat(admin-ui): Add `availableLocales` support to `I18nService`
HoseinGhanbari Nov 29, 2023
7a3a43a
feat(admin-ui): Add validation login and initialization logic require…
HoseinGhanbari Nov 29, 2023
4f33ad9
fix(admin-ui): Remove redundant `modalCurrentLocale` & `modalCurrentL…
HoseinGhanbari Nov 29, 2023
9ef0a2c
fix(admin-ui): Remove unnecessary `availableLocales` initialization
HoseinGhanbari Nov 29, 2023
ab785a1
fix(admin-ui): Make `MockI18nService` compatible with new `I18nService`
HoseinGhanbari Nov 29, 2023
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
254 changes: 253 additions & 1 deletion packages/admin-ui-plugin/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
export const DEFAULT_APP_PATH = path.join(__dirname, '../admin-ui');
export const loggerCtx = 'AdminUiPlugin';
export const defaultLanguage = LanguageCode.en;
export const defaultLocale = undefined;
export const defaultLocale = 'US';

export const defaultAvailableLanguages = [
LanguageCode.he,
Expand All @@ -26,3 +26,255 @@ export const defaultAvailableLanguages = [
LanguageCode.ne,
LanguageCode.hr,
];

export const defaultAvailableLocales = [
'AF',
'AL',
'DZ',
'AS',
'AD',
'AO',
'AI',
'AQ',
'AG',
'AR',
'AM',
'AW',
'AU',
'AT',
'AZ',
'BS',
'BH',
'BD',
'BB',
'BY',
'BE',
'BZ',
'BJ',
'BM',
'BT',
'BO',
'BQ',
'BA',
'BW',
'BV',
'BR',
'IO',
'BN',
'BG',
'BF',
'BI',
'CV',
'KH',
'CM',
'CA',
'KY',
'CF',
'TD',
'CL',
'CN',
'CX',
'CC',
'CO',
'KM',
'CD',
'CG',
'CK',
'CR',
'HR',
'CU',
'CW',
'CY',
'CZ',
'CI',
'DK',
'DJ',
'DM',
'DO',
'EC',
'EG',
'SV',
'GQ',
'ER',
'EE',
'SZ',
'ET',
'FK',
'FO',
'FJ',
'FI',
'FR',
'GF',
'PF',
'TF',
'GA',
'GM',
'GE',
'DE',
'GH',
'GI',
'GR',
'GL',
'GD',
'GP',
'GU',
'GT',
'GG',
'GN',
'GW',
'GY',
'HT',
'HM',
'VA',
'HN',
'HK',
'HU',
'IS',
'IN',
'ID',
'IR',
'IQ',
'IE',
'IM',
'IL',
'IT',
'JM',
'JP',
'JE',
'JO',
'KZ',
'KE',
'KI',
'KP',
'KR',
'KW',
'KG',
'LA',
'LV',
'LB',
'LS',
'LR',
'LY',
'LI',
'LT',
'LU',
'MO',
'MG',
'MW',
'MY',
'MV',
'ML',
'MT',
'MH',
'MQ',
'MR',
'MU',
'YT',
'MX',
'FM',
'MD',
'MC',
'MN',
'ME',
'MS',
'MA',
'MZ',
'MM',
'NA',
'NR',
'NP',
'NL',
'NC',
'NZ',
'NI',
'NE',
'NG',
'NU',
'NF',
'MK',
'MP',
'NO',
'OM',
'PK',
'PW',
'PS',
'PA',
'PG',
'PY',
'PE',
'PH',
'PN',
'PL',
'PT',
'PR',
'QA',
'RO',
'RU',
'RW',
'RE',
'BL',
'SH',
'KN',
'LC',
'MF',
'PM',
'VC',
'WS',
'SM',
'ST',
'SA',
'SN',
'RS',
'SC',
'SL',
'SG',
'SX',
'SK',
'SI',
'SB',
'SO',
'ZA',
'GS',
'SS',
'ES',
'LK',
'SD',
'SR',
'SJ',
'SE',
'CH',
'SY',
'TW',
'TJ',
'TZ',
'TH',
'TL',
'TG',
'TK',
'TO',
'TT',
'TN',
'TR',
'TM',
'TC',
'TV',
'UG',
'UA',
'AE',
'GB',
'UM',
'US',
'UY',
'UZ',
'VU',
'VE',
'VN',
'VG',
'VI',
'WF',
'EH',
'YE',
'ZM',
'ZW',
'AX',
];
22 changes: 18 additions & 4 deletions packages/admin-ui-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { MiddlewareConsumer, NestModule } from '@nestjs/common';
import { DEFAULT_AUTH_TOKEN_HEADER_KEY, DEFAULT_CHANNEL_TOKEN_KEY } from '@vendure/common/lib/shared-constants';
import {
DEFAULT_AUTH_TOKEN_HEADER_KEY,
DEFAULT_CHANNEL_TOKEN_KEY,
} from '@vendure/common/lib/shared-constants';
import {
AdminUiAppConfig,
AdminUiAppDevModeConfig,
Expand Down Expand Up @@ -27,6 +30,7 @@ import {
defaultLocale,
DEFAULT_APP_PATH,
loggerCtx,
defaultAvailableLocales,
} from './constants';
import { MetricsService } from './service/metrics.service';

Expand Down Expand Up @@ -257,8 +261,17 @@ export class AdminUiPlugin implements NestModule {
const propOrDefault = <Prop extends keyof AdminUiConfig>(
prop: Prop,
defaultVal: AdminUiConfig[Prop],
isArray: boolean = false,
): AdminUiConfig[Prop] => {
return partialConfig ? (partialConfig as AdminUiConfig)[prop] || defaultVal : defaultVal;
if (isArray) {
const isValidArray = !!partialConfig
? !!((partialConfig as AdminUiConfig)[prop] as any[])?.length
: false;

return !!partialConfig && isValidArray ? (partialConfig as AdminUiConfig)[prop] : defaultVal;
} else {
return partialConfig ? (partialConfig as AdminUiConfig)[prop] || defaultVal : defaultVal;
}
};
return {
adminApiPath: propOrDefault('adminApiPath', apiOptions.adminApiPath),
Expand All @@ -274,11 +287,12 @@ export class AdminUiPlugin implements NestModule {
),
channelTokenKey: propOrDefault(
'channelTokenKey',
apiOptions.channelTokenKey || DEFAULT_CHANNEL_TOKEN_KEY
apiOptions.channelTokenKey || DEFAULT_CHANNEL_TOKEN_KEY,
),
defaultLanguage: propOrDefault('defaultLanguage', defaultLanguage),
defaultLocale: propOrDefault('defaultLocale', defaultLocale),
availableLanguages: propOrDefault('availableLanguages', defaultAvailableLanguages),
availableLanguages: propOrDefault('availableLanguages', defaultAvailableLanguages, true),
availableLocales: propOrDefault('availableLocales', defaultAvailableLocales, true),
loginUrl: options.adminUiConfig?.loginUrl,
brand: options.adminUiConfig?.brand,
hideVendureBranding: propOrDefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class AppShellComponent implements OnInit {
uiLanguageAndLocale$: LocalizationLanguageCodeType;
direction$: LocalizationDirectionType;
availableLanguages: LanguageCode[] = [];
availableLocales: string[] = [];
hideVendureBranding = getAppConfig().hideVendureBranding;
pageTitle$: Observable<string>;
mainNavExpanded$: Observable<boolean>;
Expand Down Expand Up @@ -57,6 +58,8 @@ export class AppShellComponent implements OnInit {

this.availableLanguages = this.i18nService.availableLanguages;

this.availableLocales = this.i18nService.availableLocales;

this.pageTitle$ = this.breadcrumbService.breadcrumbs$.pipe(
map(breadcrumbs => breadcrumbs[breadcrumbs.length - 1].label),
);
Expand All @@ -70,17 +73,18 @@ export class AppShellComponent implements OnInit {
this.uiLanguageAndLocale$
.pipe(
take(1),
switchMap(([currentLanguage, currentLocale]) =>
this.modalService.fromComponent(UiLanguageSwitcherDialogComponent, {
switchMap(([currentLanguage, currentLocale]) => {
return this.modalService.fromComponent(UiLanguageSwitcherDialogComponent, {
closable: true,
size: 'lg',
locals: {
availableLocales: this.availableLocales,
availableLanguages: this.availableLanguages,
currentLanguage,
currentLocale,
currentLanguage: currentLanguage,
currentLocale: currentLocale,
},
}),
),
});
}),
switchMap(result =>
result ? this.dataService.client.setUiLanguage(result[0], result[1]) : EMPTY,
),
Expand Down
Loading
Loading