@dialpad/i18n 1.22.3 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/force-pull-translations.js +2 -0
- package/bin/pull-translations.js +2 -0
- package/bin/should-pull.js +2 -0
- package/bin/translate-dialpadistan.js +2 -0
- package/bin/translation-screenshots-check.js +2 -0
- package/bin/upload-translation-service.js +2 -0
- package/dist/i18n.cjs +883 -878
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.js +883 -878
- package/dist/i18n.js.map +1 -1
- package/dist/types/index.d.ts +2 -4
- package/dist/types/index.js +1 -2
- package/{README.md → docs/README.md} +280 -84
- package/index.ts +18 -5
- package/package.json +50 -26
- package/.eslintignore +0 -1
- package/.eslintrc.cjs +0 -12
- package/.prettierignore +0 -3
- package/.rush/temp/chunked-rush-logs/i18n.build.chunks.jsonl +0 -22
- package/.rush/temp/chunked-rush-logs/i18n.format.chunks.jsonl +0 -19
- package/.rush/temp/chunked-rush-logs/i18n.lint.chunks.jsonl +0 -2
- package/.rush/temp/package-deps_build.json +0 -24
- package/.rush/temp/package-deps_format.json +0 -24
- package/.rush/temp/package-deps_lint.json +0 -24
- package/.rush/temp/shrinkwrap-deps.json +0 -12
- package/CHANGELOG.json +0 -63
- package/CHANGELOG.md +0 -30
- package/base-tsconfig.json +0 -19
- package/dialpad-i18n-1.22.2.tgz +0 -0
- package/dist/types/src/locale-manager.d.ts +0 -53
- package/dist/types/src/locale-manager.js +0 -146
- package/eslint-tsconfig.json +0 -5
- package/index.html +0 -11
- package/rush-logs/i18n.build.error.log +0 -0
- package/rush-logs/i18n.build.log +0 -22
- package/rush-logs/i18n.format.error.log +0 -0
- package/rush-logs/i18n.format.log +0 -19
- package/rush-logs/i18n.lint.error.log +0 -0
- package/rush-logs/i18n.lint.log +0 -2
- package/src/__test__/locale-manager.find.test.ts +0 -78
- package/src/__test__/locale-manager.formatters.test.ts +0 -139
- package/src/__test__/locale-manager.multiple.test.ts +0 -349
- package/src/__test__/locale-manager.test.ts +0 -511
- package/src/locale-manager.ts +0 -198
- package/tsconfig.json +0 -10
- package/vite.config.ts +0 -39
package/src/locale-manager.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import type { App } from 'vue';
|
|
2
|
-
import type {
|
|
3
|
-
LocaleManagerParams,
|
|
4
|
-
SetLocaleParams,
|
|
5
|
-
UseI18N,
|
|
6
|
-
} from '@dialpad/i18n-services/locale-manager';
|
|
7
|
-
import { computed, ref, inject } from 'vue';
|
|
8
|
-
import type { Ref } from 'vue';
|
|
9
|
-
import { BaseLocaleManager } from '@dialpad/i18n-services/locale-manager';
|
|
10
|
-
|
|
11
|
-
export const INJECTION_KEY_PREFIX = 'GLOBAL_LOCALE_MANAGER';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This is a backup storage for LocaleManagers in order to solve
|
|
15
|
-
* the constraint of having to call useI18N() inside a <script setup>.
|
|
16
|
-
*
|
|
17
|
-
* This is kinda hackish (I tried to keep it simple as well) but otherwise we're forcing consumers
|
|
18
|
-
* (i.e. Dialtone) to potentially modify their whole database
|
|
19
|
-
* and set the <script> for each components to <script setup>
|
|
20
|
-
*
|
|
21
|
-
* (I haven't found a way to do this only relying on Vue 3 capabilities T_T)
|
|
22
|
-
*/
|
|
23
|
-
export const globalLocaleManagers = new Map<string, LocaleManager>();
|
|
24
|
-
|
|
25
|
-
export class LocaleManager extends BaseLocaleManager {
|
|
26
|
-
currentLocaleProp: Ref<string | null> = ref<string | null>(null);
|
|
27
|
-
app: App | null = null;
|
|
28
|
-
|
|
29
|
-
constructor(params: LocaleManagerParams) {
|
|
30
|
-
super(params);
|
|
31
|
-
this.setCurrentLocaleProp(
|
|
32
|
-
this.determineLocale({
|
|
33
|
-
preferredLocale: params.preferredLocale,
|
|
34
|
-
allowedLocales: params.allowedLocales,
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected setCurrentLocaleProp(locale: string): void {
|
|
40
|
-
this.currentLocaleProp = ref(locale);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Registers this LocaleManager with the Vue instance so that it can
|
|
45
|
-
* be used by the {@link useI18N} hook.
|
|
46
|
-
*
|
|
47
|
-
* @param app - The Vue app to register with.
|
|
48
|
-
* @param namespace - The namespace to install the LocaleManager under.
|
|
49
|
-
* Defaults to 'default'
|
|
50
|
-
*/
|
|
51
|
-
install(app: App, namespace = 'default'): void {
|
|
52
|
-
// initializes fluent if not initialized
|
|
53
|
-
this.initFluent();
|
|
54
|
-
this.addToVue(app, namespace);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private addToVue(app: App, namespace: string): void {
|
|
58
|
-
if (!this.fluent) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
'fluent not ready, you probably want to call install(...) first',
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
this.app = app;
|
|
64
|
-
|
|
65
|
-
// Only install fluent plugin if not already installed
|
|
66
|
-
// This prevents "component i18n has already been registered" warnings
|
|
67
|
-
const isFluentInstalled = app.component('i18n') !== undefined;
|
|
68
|
-
if (!isFluentInstalled) {
|
|
69
|
-
app.use(this.fluent);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Always register this LocaleManager for injection, regardless of plugin installation
|
|
73
|
-
app.provide(parseInjectionName(namespace), this);
|
|
74
|
-
globalLocaleManagers.set(parseInjectionName(namespace), this);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Changes the locale of the {@link LocaleManager} that is currently active in
|
|
79
|
-
* the app, or the one specified by the namespace.
|
|
80
|
-
*
|
|
81
|
-
* @param args - Optional parameters to pass to the underlying
|
|
82
|
-
* {@link BaseLocaleManager#updateLocaleSettings} method.
|
|
83
|
-
* @param namespace - Optional namespace to change the locale of. If not
|
|
84
|
-
* provided, all LocaleManagers will be changed.
|
|
85
|
-
*/
|
|
86
|
-
changeLocale(args?: Partial<SetLocaleParams>, namespace?: string): void {
|
|
87
|
-
const localeManagers = namespace
|
|
88
|
-
? this.getLocaleManagerByNamespace(namespace)
|
|
89
|
-
: this.getAllLocaleManagers();
|
|
90
|
-
|
|
91
|
-
for (const localeManager of localeManagers) {
|
|
92
|
-
localeManager.updateLocaleSettings(args);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private getLocaleManagerByNamespace(namespace: string): LocaleManager[] {
|
|
97
|
-
const localeManager =
|
|
98
|
-
this.findLocaleManagerInProvides(namespace) ??
|
|
99
|
-
findLocaleManager(namespace);
|
|
100
|
-
if (!localeManager) {
|
|
101
|
-
throw new Error('LocaleManager not found!');
|
|
102
|
-
}
|
|
103
|
-
return [localeManager];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// This method mostly focuses on remain backward compatible and reduce risks when implementing new instance providing mechanisms
|
|
107
|
-
private findLocaleManagerInProvides(
|
|
108
|
-
namespace: string,
|
|
109
|
-
): LocaleManager | undefined {
|
|
110
|
-
const providedValues = this.app?._context.provides;
|
|
111
|
-
if (!providedValues) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const targetKey = parseInjectionName(namespace);
|
|
116
|
-
return this.findLocaleManagersByKeyFilter(
|
|
117
|
-
providedValues,
|
|
118
|
-
(key) => key === targetKey,
|
|
119
|
-
)[0];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private getAllLocaleManagers(): LocaleManager[] {
|
|
123
|
-
const providedValues = this.app?._context.provides;
|
|
124
|
-
if (!providedValues) {
|
|
125
|
-
throw new Error('No locale managers are set up yet!');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return this.findLocaleManagersByKeyFilter(providedValues, (key) =>
|
|
129
|
-
key.startsWith(INJECTION_KEY_PREFIX.toString()),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private findLocaleManagersByKeyFilter(
|
|
134
|
-
providedValues: Record<string | symbol, unknown>,
|
|
135
|
-
keyFilter: (key: string) => boolean,
|
|
136
|
-
): LocaleManager[] {
|
|
137
|
-
const localeManagers: LocaleManager[] = [];
|
|
138
|
-
Object.entries(providedValues).forEach(([key, value]) => {
|
|
139
|
-
if (
|
|
140
|
-
typeof key === 'string' &&
|
|
141
|
-
keyFilter(key) &&
|
|
142
|
-
value instanceof LocaleManager
|
|
143
|
-
) {
|
|
144
|
-
localeManagers.push(value);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return localeManagers;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
useI18N(namespace = 'default'): UseI18N {
|
|
152
|
-
this.initFluent();
|
|
153
|
-
const l = this;
|
|
154
|
-
return {
|
|
155
|
-
currentLocale: computed(() => this.currentLocaleProp.value),
|
|
156
|
-
setI18N: (args?: Partial<SetLocaleParams>, namespace?: string) => {
|
|
157
|
-
l.changeLocale(args, namespace);
|
|
158
|
-
},
|
|
159
|
-
get $t() {
|
|
160
|
-
return l.fluentFormat;
|
|
161
|
-
},
|
|
162
|
-
get $ta() {
|
|
163
|
-
return l.fluentFormatAttrs;
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Use i18n functionality without requiring to depend only on Vue's inject
|
|
171
|
-
* @param namespace - The namespace of the locale manager to use, defaults to 'default'
|
|
172
|
-
*/
|
|
173
|
-
export function findLocaleManager(
|
|
174
|
-
namespace: string,
|
|
175
|
-
): LocaleManager | undefined {
|
|
176
|
-
const injectionKey = parseInjectionName(namespace);
|
|
177
|
-
// Use null as default to suppress Vue injection warning when key is not found
|
|
178
|
-
const injected = inject<LocaleManager | null>(injectionKey, null);
|
|
179
|
-
return injected ?? globalLocaleManagers.get(injectionKey);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// TODO - allow custom injection key or whatever???
|
|
183
|
-
// TODO - also maybe just use getCurrentApp + the app's global config? idk.
|
|
184
|
-
export function useI18N(namespace = 'default'): UseI18N {
|
|
185
|
-
const localeManager = findLocaleManager(namespace);
|
|
186
|
-
|
|
187
|
-
if (!localeManager) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
`locale manager doesn't exist using ${namespace}. Make sure your locale manager was set up correctly`,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return localeManager.useI18N(namespace);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function parseInjectionName(namespace: string): string {
|
|
197
|
-
return `${INJECTION_KEY_PREFIX}.${namespace}`;
|
|
198
|
-
}
|
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import vue from '@vitejs/plugin-vue';
|
|
3
|
-
import { fileURLToPath, URL } from 'node:url';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
sourcemap: true,
|
|
8
|
-
minify: false,
|
|
9
|
-
rollupOptions: {
|
|
10
|
-
external: ['vue'],
|
|
11
|
-
output: {
|
|
12
|
-
preserveModules: false,
|
|
13
|
-
minifyInternalExports: false,
|
|
14
|
-
exports: 'named',
|
|
15
|
-
},
|
|
16
|
-
treeshake: 'smallest',
|
|
17
|
-
},
|
|
18
|
-
lib: {
|
|
19
|
-
entry: './index.ts',
|
|
20
|
-
formats: ['es', 'cjs'],
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
test: {
|
|
24
|
-
// Add test runner globals like test/it/describe/afterEach etc.
|
|
25
|
-
// This is required for VTL to automically call cleanup() in afterEach().
|
|
26
|
-
// See: https://vitest.dev/guide/migration.html
|
|
27
|
-
globals: true,
|
|
28
|
-
environment: 'jsdom',
|
|
29
|
-
coverage: {
|
|
30
|
-
reporter: ['html', 'json'],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
plugins: [vue()],
|
|
34
|
-
resolve: {
|
|
35
|
-
alias: {
|
|
36
|
-
'@': fileURLToPath(new URL('../src', import.meta.url)),
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
});
|