@red-hat-developer-hub/backstage-plugin-translations 0.0.1
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/CHANGELOG.md +7 -0
- package/README.md +13 -0
- package/dist/apis/I18nextTranslationApi.esm.js +301 -0
- package/dist/apis/I18nextTranslationApi.esm.js.map +1 -0
- package/dist/apis/TranslationRef.esm.js +13 -0
- package/dist/apis/TranslationRef.esm.js.map +1 -0
- package/dist/apis/TranslationResource.esm.js +13 -0
- package/dist/apis/TranslationResource.esm.js.map +1 -0
- package/dist/components/AppLanguageCard.esm.js +21 -0
- package/dist/components/AppLanguageCard.esm.js.map +1 -0
- package/dist/components/I18NextCard.esm.js +25 -0
- package/dist/components/I18NextCard.esm.js.map +1 -0
- package/dist/components/LanguageToggleCard.esm.js +10 -0
- package/dist/components/LanguageToggleCard.esm.js.map +1 -0
- package/dist/components/LoadedTranslationsTable.esm.js +120 -0
- package/dist/components/LoadedTranslationsTable.esm.js.map +1 -0
- package/dist/components/TranslationsPage.esm.js +27 -0
- package/dist/components/TranslationsPage.esm.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.esm.js +3 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/plugin.esm.js +19 -0
- package/dist/plugin.esm.js.map +1 -0
- package/dist/routes.esm.js +8 -0
- package/dist/routes.esm.js.map +1 -0
- package/package.json +69 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# translations
|
|
2
|
+
|
|
3
|
+
Welcome to the translations plugin!
|
|
4
|
+
|
|
5
|
+
_This plugin was created through the Backstage CLI_
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/translations](http://localhost:3000/translations).
|
|
10
|
+
|
|
11
|
+
You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
|
|
12
|
+
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
|
|
13
|
+
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { createInstance } from 'i18next';
|
|
2
|
+
import ObservableImpl from 'zen-observable';
|
|
3
|
+
import { isValidElement, createElement, Fragment } from 'react';
|
|
4
|
+
import { toInternalTranslationRef } from './TranslationRef.esm.js';
|
|
5
|
+
import { toInternalTranslationResource } from './TranslationResource.esm.js';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_LANGUAGE = "en";
|
|
8
|
+
function removeNulls(messages) {
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(messages).filter(
|
|
11
|
+
(e) => e[1] !== null
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
class ResourceLoader {
|
|
16
|
+
constructor(onLoad) {
|
|
17
|
+
this.onLoad = onLoad;
|
|
18
|
+
}
|
|
19
|
+
/** Loaded resources by loader key */
|
|
20
|
+
#loaded = /* @__PURE__ */ new Set();
|
|
21
|
+
/** Resource loading promises by loader key */
|
|
22
|
+
#loading = /* @__PURE__ */ new Map();
|
|
23
|
+
/** Loaders for each resource language */
|
|
24
|
+
#loaders = /* @__PURE__ */ new Map();
|
|
25
|
+
addTranslationResource(resource) {
|
|
26
|
+
const internalResource = toInternalTranslationResource(resource);
|
|
27
|
+
for (const entry of internalResource.resources) {
|
|
28
|
+
const key = this.#getLoaderKey(entry.language, internalResource.id);
|
|
29
|
+
if (!this.#loaders.has(key)) {
|
|
30
|
+
this.#loaders.set(key, entry.loader);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
#getLoaderKey(language, namespace) {
|
|
35
|
+
return `${language}/${namespace}`;
|
|
36
|
+
}
|
|
37
|
+
needsLoading(language, namespace) {
|
|
38
|
+
const key = this.#getLoaderKey(language, namespace);
|
|
39
|
+
const loader = this.#loaders.get(key);
|
|
40
|
+
if (!loader) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return !this.#loaded.has(key);
|
|
44
|
+
}
|
|
45
|
+
async load(language, namespace) {
|
|
46
|
+
const key = this.#getLoaderKey(language, namespace);
|
|
47
|
+
const loader = this.#loaders.get(key);
|
|
48
|
+
if (!loader) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (this.#loaded.has(key)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const loading = this.#loading.get(key);
|
|
55
|
+
if (loading) {
|
|
56
|
+
await loading;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const load = loader().then(
|
|
60
|
+
(result) => {
|
|
61
|
+
this.onLoad({ language, namespace, messages: result.messages });
|
|
62
|
+
this.#loaded.add(key);
|
|
63
|
+
},
|
|
64
|
+
(error) => {
|
|
65
|
+
this.#loaded.add(key);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
this.#loading.set(key, load);
|
|
70
|
+
await load;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class JsxInterpolator {
|
|
74
|
+
#setFormatHook;
|
|
75
|
+
#marker;
|
|
76
|
+
#pattern;
|
|
77
|
+
static fromI18n(i18n) {
|
|
78
|
+
const interpolator = i18n.services.interpolator;
|
|
79
|
+
const originalFormat = interpolator.format;
|
|
80
|
+
let formatHook;
|
|
81
|
+
interpolator.format = (value, format, lng, formatOpts) => {
|
|
82
|
+
if (format) {
|
|
83
|
+
return originalFormat(value, format, lng, formatOpts);
|
|
84
|
+
}
|
|
85
|
+
return formatHook?.(value, format, lng, formatOpts) ?? value;
|
|
86
|
+
};
|
|
87
|
+
return new JsxInterpolator(
|
|
88
|
+
// Using a random marker to ensure it can't be misused
|
|
89
|
+
Math.random().toString(36).substring(2, 8),
|
|
90
|
+
(hook) => {
|
|
91
|
+
formatHook = hook;
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
constructor(marker, setFormatHook) {
|
|
96
|
+
this.#setFormatHook = setFormatHook;
|
|
97
|
+
this.#marker = marker;
|
|
98
|
+
this.#pattern = new RegExp(`\\$${marker}\\(([^)]+)\\)`);
|
|
99
|
+
}
|
|
100
|
+
wrapT(originalT) {
|
|
101
|
+
return ((key, options) => {
|
|
102
|
+
let elementsMap = void 0;
|
|
103
|
+
this.#setFormatHook((value) => {
|
|
104
|
+
if (isValidElement(value)) {
|
|
105
|
+
if (!elementsMap) {
|
|
106
|
+
elementsMap = /* @__PURE__ */ new Map();
|
|
107
|
+
}
|
|
108
|
+
const elementKey = elementsMap.size.toString();
|
|
109
|
+
elementsMap.set(elementKey, value);
|
|
110
|
+
return `$${this.#marker}(${elementKey})`;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
});
|
|
114
|
+
const result = originalT(key, options);
|
|
115
|
+
if (!elementsMap) {
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
const split = result.split(this.#pattern);
|
|
119
|
+
return createElement(
|
|
120
|
+
Fragment,
|
|
121
|
+
null,
|
|
122
|
+
...split.map((part, index) => {
|
|
123
|
+
if (index % 2 === 0) {
|
|
124
|
+
return part;
|
|
125
|
+
}
|
|
126
|
+
return elementsMap?.get(part);
|
|
127
|
+
}).filter(Boolean)
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class I18nextTranslationApi {
|
|
133
|
+
static create(options) {
|
|
134
|
+
const { languages } = options.languageApi.getAvailableLanguages();
|
|
135
|
+
const i18n = createInstance({
|
|
136
|
+
fallbackLng: DEFAULT_LANGUAGE,
|
|
137
|
+
supportedLngs: languages,
|
|
138
|
+
interpolation: {
|
|
139
|
+
escapeValue: false,
|
|
140
|
+
// Used for the JsxInterpolator format hook
|
|
141
|
+
alwaysFormat: true
|
|
142
|
+
},
|
|
143
|
+
ns: [],
|
|
144
|
+
defaultNS: false,
|
|
145
|
+
fallbackNS: false,
|
|
146
|
+
// Disable resource loading on init, meaning i18n will be ready to use immediately
|
|
147
|
+
initImmediate: false
|
|
148
|
+
});
|
|
149
|
+
i18n.init();
|
|
150
|
+
if (!i18n.isInitialized) {
|
|
151
|
+
throw new Error("i18next was unexpectedly not initialized");
|
|
152
|
+
}
|
|
153
|
+
const interpolator = JsxInterpolator.fromI18n(i18n);
|
|
154
|
+
const { language: initialLanguage } = options.languageApi.getLanguage();
|
|
155
|
+
if (initialLanguage !== DEFAULT_LANGUAGE) {
|
|
156
|
+
i18n.changeLanguage(initialLanguage);
|
|
157
|
+
}
|
|
158
|
+
const loader = new ResourceLoader((loaded) => {
|
|
159
|
+
i18n.addResourceBundle(
|
|
160
|
+
loaded.language,
|
|
161
|
+
loaded.namespace,
|
|
162
|
+
removeNulls(loaded.messages),
|
|
163
|
+
false,
|
|
164
|
+
// do not merge with existing translations
|
|
165
|
+
true
|
|
166
|
+
// overwrite translations
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
const resources = options?.resources || [];
|
|
170
|
+
for (let i = resources.length - 1; i >= 0; i--) {
|
|
171
|
+
const resource = resources[i];
|
|
172
|
+
if (resource.$$type === "@backstage/TranslationResource") {
|
|
173
|
+
loader.addTranslationResource(resource);
|
|
174
|
+
} else if (resource.$$type === "@backstage/TranslationMessages") {
|
|
175
|
+
i18n.addResourceBundle(
|
|
176
|
+
DEFAULT_LANGUAGE,
|
|
177
|
+
resource.id,
|
|
178
|
+
removeNulls(resource.messages),
|
|
179
|
+
true,
|
|
180
|
+
// merge with existing translations
|
|
181
|
+
false
|
|
182
|
+
// do not overwrite translations
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const instance = new I18nextTranslationApi(
|
|
187
|
+
i18n,
|
|
188
|
+
loader,
|
|
189
|
+
options.languageApi.getLanguage().language,
|
|
190
|
+
interpolator
|
|
191
|
+
);
|
|
192
|
+
options.languageApi.language$().subscribe(({ language }) => {
|
|
193
|
+
instance.#changeLanguage(language);
|
|
194
|
+
});
|
|
195
|
+
return instance;
|
|
196
|
+
}
|
|
197
|
+
#i18n;
|
|
198
|
+
#loader;
|
|
199
|
+
#language;
|
|
200
|
+
#jsxInterpolator;
|
|
201
|
+
/** Keep track of which refs we have registered default resources for */
|
|
202
|
+
#registeredRefs = /* @__PURE__ */ new Set();
|
|
203
|
+
/** Notify observers when language changes */
|
|
204
|
+
#languageChangeListeners = /* @__PURE__ */ new Set();
|
|
205
|
+
constructor(i18n, loader, language, jsxInterpolator) {
|
|
206
|
+
this.#i18n = i18n;
|
|
207
|
+
this.#loader = loader;
|
|
208
|
+
this.#language = language;
|
|
209
|
+
this.#jsxInterpolator = jsxInterpolator;
|
|
210
|
+
}
|
|
211
|
+
getI18nInstance() {
|
|
212
|
+
return this.#i18n;
|
|
213
|
+
}
|
|
214
|
+
getTranslation(translationRef) {
|
|
215
|
+
const internalRef = toInternalTranslationRef(translationRef);
|
|
216
|
+
this.#registerDefaults(internalRef);
|
|
217
|
+
return this.#createSnapshot(internalRef);
|
|
218
|
+
}
|
|
219
|
+
translation$(translationRef) {
|
|
220
|
+
const internalRef = toInternalTranslationRef(translationRef);
|
|
221
|
+
this.#registerDefaults(internalRef);
|
|
222
|
+
return new ObservableImpl((subscriber) => {
|
|
223
|
+
let loadTicket = {};
|
|
224
|
+
const loadResource = () => {
|
|
225
|
+
loadTicket = {};
|
|
226
|
+
const ticket = loadTicket;
|
|
227
|
+
this.#loader.load(this.#language, internalRef.id).then(
|
|
228
|
+
() => {
|
|
229
|
+
if (ticket === loadTicket) {
|
|
230
|
+
const snapshot = this.#createSnapshot(internalRef);
|
|
231
|
+
if (snapshot.ready) {
|
|
232
|
+
subscriber.next(snapshot);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
(error) => {
|
|
237
|
+
if (ticket === loadTicket) {
|
|
238
|
+
subscriber.error(Array.isArray(error) ? error[0] : error);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
const onChange = () => {
|
|
244
|
+
const snapshot = this.#createSnapshot(internalRef);
|
|
245
|
+
if (snapshot.ready) {
|
|
246
|
+
subscriber.next(snapshot);
|
|
247
|
+
} else {
|
|
248
|
+
loadResource();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
if (this.#loader.needsLoading(this.#language, internalRef.id)) {
|
|
252
|
+
loadResource();
|
|
253
|
+
}
|
|
254
|
+
this.#languageChangeListeners.add(onChange);
|
|
255
|
+
return () => {
|
|
256
|
+
this.#languageChangeListeners.delete(onChange);
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
#changeLanguage(language) {
|
|
261
|
+
if (this.#language !== language) {
|
|
262
|
+
this.#language = language;
|
|
263
|
+
this.#i18n.changeLanguage(language);
|
|
264
|
+
this.#languageChangeListeners.forEach((listener) => listener());
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
#createSnapshot(internalRef) {
|
|
268
|
+
if (this.#loader.needsLoading(this.#language, internalRef.id)) {
|
|
269
|
+
return { ready: false };
|
|
270
|
+
}
|
|
271
|
+
const unwrappedT = this.#i18n.getFixedT(null, internalRef.id);
|
|
272
|
+
const t = this.#jsxInterpolator.wrapT(unwrappedT);
|
|
273
|
+
return {
|
|
274
|
+
ready: true,
|
|
275
|
+
t
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
#registerDefaults(internalRef) {
|
|
279
|
+
if (this.#registeredRefs.has(internalRef.id)) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
this.#registeredRefs.add(internalRef.id);
|
|
283
|
+
const defaultMessages = internalRef.getDefaultMessages();
|
|
284
|
+
this.#i18n.addResourceBundle(
|
|
285
|
+
DEFAULT_LANGUAGE,
|
|
286
|
+
internalRef.id,
|
|
287
|
+
defaultMessages,
|
|
288
|
+
true,
|
|
289
|
+
// merge with existing translations
|
|
290
|
+
false
|
|
291
|
+
// do not overwrite translations
|
|
292
|
+
);
|
|
293
|
+
const defaultResource = internalRef.getDefaultResource();
|
|
294
|
+
if (defaultResource) {
|
|
295
|
+
this.#loader.addTranslationResource(defaultResource);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export { I18nextTranslationApi, JsxInterpolator };
|
|
301
|
+
//# sourceMappingURL=I18nextTranslationApi.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18nextTranslationApi.esm.js","sources":["../../src/apis/I18nextTranslationApi.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AppLanguageApi,\n TranslationApi,\n TranslationFunction,\n TranslationMessages,\n TranslationRef,\n TranslationResource,\n TranslationSnapshot,\n} from '@backstage/core-plugin-api/alpha';\nimport {\n createInstance as createI18n,\n FormatFunction,\n Interpolator,\n TFunction,\n type i18n as I18n,\n} from 'i18next';\nimport ObservableImpl from 'zen-observable';\n\nimport { Observable } from '@backstage/types';\nimport { createElement, Fragment, ReactNode, isValidElement } from 'react';\nimport {\n InternalTranslationRef,\n toInternalTranslationRef,\n} from './TranslationRef';\nimport {\n InternalTranslationResourceLoader,\n toInternalTranslationResource,\n} from './TranslationResource';\n\nconst DEFAULT_LANGUAGE = 'en';\n\n/** @public */\nexport interface I18nextTranslationApiOptions {\n languageApi: AppLanguageApi;\n resources?: Array<TranslationMessages | TranslationResource>;\n}\n\nfunction removeNulls(\n messages: Record<string, string | null>,\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(messages).filter(\n (e): e is [string, string] => e[1] !== null,\n ),\n );\n}\n\n/**\n * The built-in i18next backend loading logic doesn't handle on the fly switches\n * of language very well. It gets a bit confused about whether resources are actually\n * loaded or not, so instead we implement our own resource loader.\n */\nclass ResourceLoader {\n /** Loaded resources by loader key */\n #loaded = new Set<string>();\n /** Resource loading promises by loader key */\n #loading = new Map<string, Promise<void>>();\n /** Loaders for each resource language */\n #loaders = new Map<string, InternalTranslationResourceLoader>();\n\n constructor(\n private readonly onLoad: (loaded: {\n language: string;\n namespace: string;\n messages: Record<string, string | null>;\n }) => void,\n ) {}\n\n addTranslationResource(resource: TranslationResource) {\n const internalResource = toInternalTranslationResource(resource);\n for (const entry of internalResource.resources) {\n const key = this.#getLoaderKey(entry.language, internalResource.id);\n\n // First loader to register wins, this means that resources registered in the app\n // have priority over default resource from translation refs\n if (!this.#loaders.has(key)) {\n this.#loaders.set(key, entry.loader);\n }\n }\n }\n\n #getLoaderKey(language: string, namespace: string) {\n return `${language}/${namespace}`;\n }\n\n needsLoading(language: string, namespace: string) {\n const key = this.#getLoaderKey(language, namespace);\n const loader = this.#loaders.get(key);\n if (!loader) {\n return false;\n }\n\n return !this.#loaded.has(key);\n }\n\n async load(language: string, namespace: string): Promise<void> {\n const key = this.#getLoaderKey(language, namespace);\n\n const loader = this.#loaders.get(key);\n if (!loader) {\n return;\n }\n\n if (this.#loaded.has(key)) {\n return;\n }\n\n const loading = this.#loading.get(key);\n if (loading) {\n await loading;\n return;\n }\n\n const load = loader().then(\n result => {\n this.onLoad({ language, namespace, messages: result.messages });\n this.#loaded.add(key);\n },\n error => {\n this.#loaded.add(key); // Do not try to load failed resources again\n throw error;\n },\n );\n this.#loading.set(key, load);\n await load;\n }\n}\n\n/**\n * A helper for implementing JSX interpolation\n */\nexport class JsxInterpolator {\n readonly #setFormatHook: (hook: FormatFunction) => void;\n readonly #marker: string;\n readonly #pattern: RegExp;\n\n static fromI18n(i18n: I18n) {\n const interpolator = i18n.services.interpolator as Interpolator & {\n format: FormatFunction;\n };\n const originalFormat = interpolator.format;\n\n let formatHook: FormatFunction | undefined;\n\n // This is the only way to override the format function of the interpolator\n // without overriding the default formatters. See the behavior here:\n // https://github.com/i18next/i18next/blob/c633121e57e2b6024080142d78027842bf2a6e5e/src/i18next.js#L120-L125\n interpolator.format = (value, format, lng, formatOpts) => {\n if (format) {\n return originalFormat(value, format, lng, formatOpts);\n }\n return formatHook?.(value, format, lng, formatOpts) ?? value;\n };\n\n return new JsxInterpolator(\n // Using a random marker to ensure it can't be misused\n Math.random().toString(36).substring(2, 8),\n hook => {\n formatHook = hook;\n },\n );\n }\n\n private constructor(\n marker: string,\n setFormatHook: (hook: FormatFunction) => void,\n ) {\n this.#setFormatHook = setFormatHook;\n this.#marker = marker;\n this.#pattern = new RegExp(`\\\\$${marker}\\\\(([^)]+)\\\\)`);\n }\n\n wrapT<TMessages extends { [key in string]: string }>(\n originalT: TFunction,\n ): TranslationFunction<TMessages> {\n return ((key, options) => {\n let elementsMap: Map<string, ReactNode> | undefined = undefined;\n\n // There's no way to override the format hook via the translation function\n // options, event though types indicate that it might be possible.\n // Instead, override the format function hook before every invocation and\n // rely on synchronous execution.\n this.#setFormatHook(value => {\n if (isValidElement(value)) {\n if (!elementsMap) {\n elementsMap = new Map();\n }\n const elementKey = elementsMap.size.toString();\n elementsMap.set(elementKey, value);\n\n return `$${this.#marker}(${elementKey})`;\n }\n return value;\n });\n\n // Overriding the return options is not allowed via TranslationFunction,\n // so this will always be a string\n const result = originalT(key, options as any) as unknown as string;\n if (!elementsMap) {\n return result;\n }\n\n const split = result.split(this.#pattern);\n\n return createElement(\n Fragment,\n null,\n ...split\n .map((part, index) => {\n if (index % 2 === 0) {\n return part;\n }\n return elementsMap?.get(part);\n })\n .filter(Boolean),\n );\n }) as TranslationFunction<TMessages>;\n }\n}\n\n/** @public */\nexport class I18nextTranslationApi implements TranslationApi {\n static create(options: I18nextTranslationApiOptions) {\n const { languages } = options.languageApi.getAvailableLanguages();\n\n const i18n = createI18n({\n fallbackLng: DEFAULT_LANGUAGE,\n supportedLngs: languages,\n interpolation: {\n escapeValue: false,\n // Used for the JsxInterpolator format hook\n alwaysFormat: true,\n },\n ns: [],\n defaultNS: false,\n fallbackNS: false,\n\n // Disable resource loading on init, meaning i18n will be ready to use immediately\n initImmediate: false,\n });\n\n i18n.init();\n if (!i18n.isInitialized) {\n throw new Error('i18next was unexpectedly not initialized');\n }\n\n const interpolator = JsxInterpolator.fromI18n(i18n);\n\n const { language: initialLanguage } = options.languageApi.getLanguage();\n if (initialLanguage !== DEFAULT_LANGUAGE) {\n i18n.changeLanguage(initialLanguage);\n }\n\n const loader = new ResourceLoader(loaded => {\n i18n.addResourceBundle(\n loaded.language,\n loaded.namespace,\n removeNulls(loaded.messages),\n false, // do not merge with existing translations\n true, // overwrite translations\n );\n });\n\n const resources = options?.resources || [];\n // Iterate in reverse, giving higher priority to resources registered later\n for (let i = resources.length - 1; i >= 0; i--) {\n const resource = resources[i];\n if (resource.$$type === '@backstage/TranslationResource') {\n loader.addTranslationResource(resource);\n } else if (resource.$$type === '@backstage/TranslationMessages') {\n // Overrides for default messages, created with createTranslationMessages and installed via app\n i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n resource.id,\n removeNulls(resource.messages),\n true, // merge with existing translations\n false, // do not overwrite translations\n );\n }\n }\n\n const instance = new I18nextTranslationApi(\n i18n,\n loader,\n options.languageApi.getLanguage().language,\n interpolator,\n );\n\n options.languageApi.language$().subscribe(({ language }) => {\n instance.#changeLanguage(language);\n });\n\n return instance;\n }\n\n #i18n: I18n;\n #loader: ResourceLoader;\n #language: string;\n #jsxInterpolator: JsxInterpolator;\n\n /** Keep track of which refs we have registered default resources for */\n #registeredRefs = new Set<string>();\n /** Notify observers when language changes */\n #languageChangeListeners = new Set<() => void>();\n\n private constructor(\n i18n: I18n,\n loader: ResourceLoader,\n language: string,\n jsxInterpolator: JsxInterpolator,\n ) {\n this.#i18n = i18n;\n this.#loader = loader;\n this.#language = language;\n this.#jsxInterpolator = jsxInterpolator;\n }\n\n getI18nInstance(): I18n {\n return this.#i18n;\n }\n\n getTranslation<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n this.#registerDefaults(internalRef);\n\n return this.#createSnapshot(internalRef);\n }\n\n translation$<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): Observable<TranslationSnapshot<TMessages>> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n this.#registerDefaults(internalRef);\n\n return new ObservableImpl<TranslationSnapshot<TMessages>>(subscriber => {\n let loadTicket = {}; // To check for stale loads\n\n const loadResource = () => {\n loadTicket = {};\n const ticket = loadTicket;\n this.#loader.load(this.#language, internalRef.id).then(\n () => {\n if (ticket === loadTicket) {\n const snapshot = this.#createSnapshot(internalRef);\n if (snapshot.ready) {\n subscriber.next(snapshot);\n }\n }\n },\n error => {\n if (ticket === loadTicket) {\n subscriber.error(Array.isArray(error) ? error[0] : error);\n }\n },\n );\n };\n\n const onChange = () => {\n const snapshot = this.#createSnapshot(internalRef);\n if (snapshot.ready) {\n subscriber.next(snapshot);\n } else {\n loadResource();\n }\n };\n\n if (this.#loader.needsLoading(this.#language, internalRef.id)) {\n loadResource();\n }\n\n this.#languageChangeListeners.add(onChange);\n return () => {\n this.#languageChangeListeners.delete(onChange);\n };\n });\n }\n\n #changeLanguage(language: string): void {\n if (this.#language !== language) {\n this.#language = language;\n this.#i18n.changeLanguage(language);\n this.#languageChangeListeners.forEach(listener => listener());\n }\n }\n\n #createSnapshot<TMessages extends { [key in string]: string }>(\n internalRef: InternalTranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n if (this.#loader.needsLoading(this.#language, internalRef.id)) {\n return { ready: false };\n }\n\n const unwrappedT = this.#i18n.getFixedT(null, internalRef.id);\n const t = this.#jsxInterpolator.wrapT<TMessages>(unwrappedT);\n\n return {\n ready: true,\n t,\n };\n }\n\n #registerDefaults(internalRef: InternalTranslationRef): void {\n if (this.#registeredRefs.has(internalRef.id)) {\n return;\n }\n this.#registeredRefs.add(internalRef.id);\n\n const defaultMessages = internalRef.getDefaultMessages();\n this.#i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n internalRef.id,\n defaultMessages,\n true, // merge with existing translations\n false, // do not overwrite translations\n );\n\n const defaultResource = internalRef.getDefaultResource();\n if (defaultResource) {\n this.#loader.addTranslationResource(defaultResource);\n }\n }\n}\n"],"names":["createI18n"],"mappings":";;;;;;AA6CA,MAAM,gBAAA,GAAmB,IAAA;AAQzB,SAAS,YACP,QAAA,EACwB;AACxB,EAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IACZ,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAA,CAAE,MAAA;AAAA,MACvB,CAAC,CAAA,KAA6B,CAAA,CAAE,CAAC,CAAA,KAAM;AAAA;AACzC,GACF;AACF;AAOA,MAAM,cAAA,CAAe;AAAA,EAQnB,YACmB,MAAA,EAKjB;AALiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAKhB;AAAA;AAAA,EAZH,OAAA,uBAAc,GAAA,EAAY;AAAA;AAAA,EAE1B,QAAA,uBAAe,GAAA,EAA2B;AAAA;AAAA,EAE1C,QAAA,uBAAe,GAAA,EAA+C;AAAA,EAU9D,uBAAuB,QAAA,EAA+B;AACpD,IAAA,MAAM,gBAAA,GAAmB,8BAA8B,QAAQ,CAAA;AAC/D,IAAA,KAAA,MAAW,KAAA,IAAS,iBAAiB,SAAA,EAAW;AAC9C,MAAA,MAAM,MAAM,IAAA,CAAK,aAAA,CAAc,KAAA,CAAM,QAAA,EAAU,iBAAiB,EAAE,CAAA;AAIlE,MAAA,IAAI,CAAC,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA,EAAG;AAC3B,QAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI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AAC3D,IAAA,IAAI,IAAA,CAAK,eAAA,CAAgB,GAAA,CAAI,WAAA,CAAY,EAAE,CAAA,EAAG;AAC5C,MAAA;AAAA,IACF;AACA,IAAA,IAAA,CAAK,eAAA,CAAgB,GAAA,CAAI,WAAA,CAAY,EAAE,CAAA;AAEvC,IAAA,MAAM,eAAA,GAAkB,YAAY,kBAAA,EAAmB;AACvD,IAAA,IAAA,CAAK,KAAA,CAAM,iBAAA;AAAA,MACT,gBAAA;AAAA,MACA,WAAA,CAAY,EAAA;AAAA,MACZ,eAAA;AAAA,MACA,IAAA;AAAA;AAAA,MACA;AAAA;AAAA,KACF;AAEA,IAAA,MAAM,eAAA,GAAkB,YAAY,kBAAA,EAAmB;AACvD,IAAA,IAAI,eAAA,EAAiB;AACnB,MAAA,IAAA,CAAK,OAAA,CAAQ,uBAAuB,eAAe,CAAA;AAAA,IACrD;AAAA,EACF;AACF;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function toInternalTranslationRef(ref) {
|
|
2
|
+
const r = ref;
|
|
3
|
+
if (r.$$type !== "@backstage/TranslationRef") {
|
|
4
|
+
throw new Error(`Invalid translation ref, bad type '${r.$$type}'`);
|
|
5
|
+
}
|
|
6
|
+
if (r.version !== "v1") {
|
|
7
|
+
throw new Error(`Invalid translation ref, bad version '${r.version}'`);
|
|
8
|
+
}
|
|
9
|
+
return r;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { toInternalTranslationRef };
|
|
13
|
+
//# sourceMappingURL=TranslationRef.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranslationRef.esm.js","sources":["../../src/apis/TranslationRef.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n TranslationRef,\n TranslationResource,\n} from '@backstage/core-plugin-api/alpha';\n\n/** @internal */\ntype AnyMessages = { [key in string]: string };\n\n/** @internal */\nexport interface InternalTranslationRef<\n TId extends string = string,\n TMessages extends { [key in string]: string } = { [key in string]: string },\n> extends TranslationRef<TId, TMessages> {\n version: 'v1';\n\n getDefaultMessages(): AnyMessages;\n\n getDefaultResource(): TranslationResource | undefined;\n}\n\n/** @internal */\nexport function toInternalTranslationRef<\n TId extends string,\n TMessages extends AnyMessages,\n>(ref: TranslationRef<TId, TMessages>): InternalTranslationRef<TId, TMessages> {\n const r = ref as InternalTranslationRef<TId, TMessages>;\n if (r.$$type !== '@backstage/TranslationRef') {\n throw new Error(`Invalid translation ref, bad type '${r.$$type}'`);\n }\n if (r.version !== 'v1') {\n throw new Error(`Invalid translation ref, bad version '${r.version}'`);\n }\n return r;\n}\n"],"names":[],"mappings":"AAoCO,SAAS,yBAGd,GAAA,EAA6E;AAC7E,EAAA,MAAM,CAAA,GAAI,GAAA;AACV,EAAA,IAAI,CAAA,CAAE,WAAW,2BAAA,EAA6B;AAC5C,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mCAAA,EAAsC,CAAA,CAAE,MAAM,CAAA,CAAA,CAAG,CAAA;AAAA,EACnE;AACA,EAAA,IAAI,CAAA,CAAE,YAAY,IAAA,EAAM;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,sCAAA,EAAyC,CAAA,CAAE,OAAO,CAAA,CAAA,CAAG,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function toInternalTranslationResource(resource) {
|
|
2
|
+
const r = resource;
|
|
3
|
+
if (r.$$type !== "@backstage/TranslationResource") {
|
|
4
|
+
throw new Error(`Invalid translation resource, bad type '${r.$$type}'`);
|
|
5
|
+
}
|
|
6
|
+
if (r.version !== "v1") {
|
|
7
|
+
throw new Error(`Invalid translation resource, bad version '${r.version}'`);
|
|
8
|
+
}
|
|
9
|
+
return r;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { toInternalTranslationResource };
|
|
13
|
+
//# sourceMappingURL=TranslationResource.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranslationResource.esm.js","sources":["../../src/apis/TranslationResource.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { TranslationResource } from '@backstage/core-plugin-api/alpha';\n\n/** @internal */\nexport type InternalTranslationResourceLoader = () => Promise<{\n messages: { [key in string]: string | null };\n}>;\n\n/** @internal */\nexport interface InternalTranslationResource<TId extends string = string>\n extends TranslationResource<TId> {\n version: 'v1';\n resources: Array<{\n language: string;\n loader: InternalTranslationResourceLoader;\n }>;\n}\n\n/** @internal */\nexport function toInternalTranslationResource<TId extends string>(\n resource: TranslationResource<TId>,\n): InternalTranslationResource<TId> {\n const r = resource as InternalTranslationResource<TId>;\n if (r.$$type !== '@backstage/TranslationResource') {\n throw new Error(`Invalid translation resource, bad type '${r.$$type}'`);\n }\n if (r.version !== 'v1') {\n throw new Error(`Invalid translation resource, bad version '${r.version}'`);\n }\n\n return r;\n}\n"],"names":[],"mappings":"AAiCO,SAAS,8BACd,QAAA,EACkC;AAClC,EAAA,MAAM,CAAA,GAAI,QAAA;AACV,EAAA,IAAI,CAAA,CAAE,WAAW,gCAAA,EAAkC;AACjD,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,wCAAA,EAA2C,CAAA,CAAE,MAAM,CAAA,CAAA,CAAG,CAAA;AAAA,EACxE;AACA,EAAA,IAAI,CAAA,CAAE,YAAY,IAAA,EAAM;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2CAAA,EAA8C,CAAA,CAAE,OAAO,CAAA,CAAA,CAAG,CAAA;AAAA,EAC5E;AAEA,EAAA,OAAO,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { InfoCard } from '@backstage/core-components';
|
|
3
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
4
|
+
import { appLanguageApiRef } from '@backstage/core-plugin-api/alpha';
|
|
5
|
+
|
|
6
|
+
const AppLanguageCard = () => {
|
|
7
|
+
const appLanguageApi = useApi(appLanguageApiRef);
|
|
8
|
+
return /* @__PURE__ */ jsxs(InfoCard, { title: "AppLanguageApi", children: [
|
|
9
|
+
/* @__PURE__ */ jsx("strong", { children: "Current Language:" }),
|
|
10
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
11
|
+
appLanguageApi.getLanguage().language,
|
|
12
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
13
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
14
|
+
/* @__PURE__ */ jsx("strong", { children: "Available languages:" }),
|
|
15
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
16
|
+
appLanguageApi.getAvailableLanguages().languages.map((lang) => /* @__PURE__ */ jsx("div", { children: lang }, lang))
|
|
17
|
+
] });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { AppLanguageCard };
|
|
21
|
+
//# sourceMappingURL=AppLanguageCard.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppLanguageCard.esm.js","sources":["../../src/components/AppLanguageCard.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { InfoCard } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { appLanguageApiRef } from '@backstage/core-plugin-api/alpha';\n\nexport const AppLanguageCard = () => {\n const appLanguageApi = useApi(appLanguageApiRef);\n\n return (\n <InfoCard title=\"AppLanguageApi\">\n <strong>Current Language:</strong>\n <br />\n {appLanguageApi.getLanguage().language}\n <br />\n <br />\n\n <strong>Available languages:</strong>\n <br />\n {appLanguageApi.getAvailableLanguages().languages.map(lang => (\n <div key={lang}>{lang}</div>\n ))}\n </InfoCard>\n );\n};\n"],"names":[],"mappings":";;;;;AAmBO,MAAM,kBAAkB,MAAM;AACnC,EAAA,MAAM,cAAA,GAAiB,OAAO,iBAAiB,CAAA;AAE/C,EAAA,uBACE,IAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAM,gBAAA,EACd,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,YAAO,QAAA,EAAA,mBAAA,EAAiB,CAAA;AAAA,wBACxB,IAAA,EAAA,EAAG,CAAA;AAAA,IACH,cAAA,CAAe,aAAY,CAAE,QAAA;AAAA,wBAC7B,IAAA,EAAA,EAAG,CAAA;AAAA,wBACH,IAAA,EAAA,EAAG,CAAA;AAAA,oBAEJ,GAAA,CAAC,YAAO,QAAA,EAAA,sBAAA,EAAoB,CAAA;AAAA,wBAC3B,IAAA,EAAA,EAAG,CAAA;AAAA,IACH,cAAA,CAAe,qBAAA,EAAsB,CAAE,SAAA,CAAU,GAAA,CAAI,0BACpD,GAAA,CAAC,KAAA,EAAA,EAAgB,QAAA,EAAA,IAAA,EAAA,EAAP,IAAY,CACvB;AAAA,GAAA,EACH,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { InfoCard } from '@backstage/core-components';
|
|
3
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
4
|
+
import { translationApiRef } from '@backstage/core-plugin-api/alpha';
|
|
5
|
+
|
|
6
|
+
const I18NextCard = () => {
|
|
7
|
+
const translationApi = useApi(translationApiRef);
|
|
8
|
+
const i18n = translationApi.getI18nInstance();
|
|
9
|
+
return /* @__PURE__ */ jsxs(InfoCard, { title: "TranslationApi / i18Next", children: [
|
|
10
|
+
/* @__PURE__ */ jsx("strong", { children: "Current Language:" }),
|
|
11
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
12
|
+
i18n.language,
|
|
13
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
14
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
15
|
+
/* @__PURE__ */ jsx("strong", { children: "Available languages:" }),
|
|
16
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
17
|
+
i18n.languages?.map((lang) => /* @__PURE__ */ jsx("div", { children: lang }, lang)),
|
|
18
|
+
/* @__PURE__ */ jsx("strong", { children: "Available languages:" }),
|
|
19
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
20
|
+
/* @__PURE__ */ jsx("pre", { children: JSON.stringify(i18n.store.data, null, 2) })
|
|
21
|
+
] });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { I18NextCard };
|
|
25
|
+
//# sourceMappingURL=I18NextCard.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18NextCard.esm.js","sources":["../../src/components/I18NextCard.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { InfoCard } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { translationApiRef } from '@backstage/core-plugin-api/alpha';\n\nimport type { i18n as I18n } from 'i18next';\n\nexport const I18NextCard = () => {\n const translationApi = useApi(translationApiRef);\n const i18n: I18n = (translationApi as any).getI18nInstance();\n\n return (\n <InfoCard title=\"TranslationApi / i18Next\">\n <strong>Current Language:</strong>\n <br />\n {i18n.language}\n <br />\n <br />\n\n <strong>Available languages:</strong>\n <br />\n {i18n.languages?.map(lang => (\n <div key={lang}>{lang}</div>\n ))}\n\n <strong>Available languages:</strong>\n <br />\n <pre>{JSON.stringify(i18n.store.data, null, 2)}</pre>\n </InfoCard>\n );\n};\n"],"names":[],"mappings":";;;;;AAqBO,MAAM,cAAc,MAAM;AAC/B,EAAA,MAAM,cAAA,GAAiB,OAAO,iBAAiB,CAAA;AAC/C,EAAA,MAAM,IAAA,GAAc,eAAuB,eAAA,EAAgB;AAE3D,EAAA,uBACE,IAAA,CAAC,QAAA,EAAA,EAAS,KAAA,EAAM,0BAAA,EACd,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,YAAO,QAAA,EAAA,mBAAA,EAAiB,CAAA;AAAA,wBACxB,IAAA,EAAA,EAAG,CAAA;AAAA,IACH,IAAA,CAAK,QAAA;AAAA,wBACL,IAAA,EAAA,EAAG,CAAA;AAAA,wBACH,IAAA,EAAA,EAAG,CAAA;AAAA,oBAEJ,GAAA,CAAC,YAAO,QAAA,EAAA,sBAAA,EAAoB,CAAA;AAAA,wBAC3B,IAAA,EAAA,EAAG,CAAA;AAAA,IACH,IAAA,CAAK,WAAW,GAAA,CAAI,CAAA,IAAA,yBAClB,KAAA,EAAA,EAAgB,QAAA,EAAA,IAAA,EAAA,EAAP,IAAY,CACvB,CAAA;AAAA,oBAED,GAAA,CAAC,YAAO,QAAA,EAAA,sBAAA,EAAoB,CAAA;AAAA,wBAC3B,IAAA,EAAA,EAAG,CAAA;AAAA,oBACJ,GAAA,CAAC,SAAK,QAAA,EAAA,IAAA,CAAK,SAAA,CAAU,KAAK,KAAA,CAAM,IAAA,EAAM,IAAA,EAAM,CAAC,CAAA,EAAE;AAAA,GAAA,EACjD,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { InfoCard } from '@backstage/core-components';
|
|
3
|
+
import { UserSettingsLanguageToggle } from '@backstage/plugin-user-settings';
|
|
4
|
+
|
|
5
|
+
const LanguageToggleCard = () => {
|
|
6
|
+
return /* @__PURE__ */ jsx(InfoCard, { title: "Language Toggle", children: /* @__PURE__ */ jsx(UserSettingsLanguageToggle, {}) });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { LanguageToggleCard };
|
|
10
|
+
//# sourceMappingURL=LanguageToggleCard.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LanguageToggleCard.esm.js","sources":["../../src/components/LanguageToggleCard.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { InfoCard } from '@backstage/core-components';\n\nimport { UserSettingsLanguageToggle } from '@backstage/plugin-user-settings';\n\nexport const LanguageToggleCard = () => {\n return (\n <InfoCard title=\"Language Toggle\">\n <UserSettingsLanguageToggle />\n </InfoCard>\n );\n};\n"],"names":[],"mappings":";;;;AAmBO,MAAM,qBAAqB,MAAM;AACtC,EAAA,2BACG,QAAA,EAAA,EAAS,KAAA,EAAM,iBAAA,EACd,QAAA,kBAAA,GAAA,CAAC,8BAA2B,CAAA,EAC9B,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Table } from '@backstage/core-components';
|
|
3
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
4
|
+
import { appLanguageApiRef, translationApiRef } from '@backstage/core-plugin-api/alpha';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
const getLanguageDisplayName = (language) => {
|
|
8
|
+
try {
|
|
9
|
+
const names = new Intl.DisplayNames([language], {
|
|
10
|
+
type: "language"
|
|
11
|
+
});
|
|
12
|
+
const languageDisplayName = names.of(language);
|
|
13
|
+
if (languageDisplayName) {
|
|
14
|
+
return `${languageDisplayName} (${language})`;
|
|
15
|
+
}
|
|
16
|
+
return language;
|
|
17
|
+
} catch (err) {
|
|
18
|
+
return language;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const getTranslation = (resources, lang, ref, key) => {
|
|
22
|
+
const resourceLang = resources[lang];
|
|
23
|
+
const resourceKey = resourceLang?.[ref];
|
|
24
|
+
const translation = typeof resourceKey === "object" ? resourceKey?.[key] : void 0;
|
|
25
|
+
return translation;
|
|
26
|
+
};
|
|
27
|
+
const LoadedTranslationsTable = () => {
|
|
28
|
+
const appLanguageApi = useApi(appLanguageApiRef);
|
|
29
|
+
const translationApi = useApi(translationApiRef);
|
|
30
|
+
const i18n = translationApi.getI18nInstance();
|
|
31
|
+
const resources = i18n.store.data;
|
|
32
|
+
const showLanguages = useMemo(
|
|
33
|
+
() => [
|
|
34
|
+
"en",
|
|
35
|
+
...appLanguageApi.getAvailableLanguages().languages.filter((lang) => lang !== "en")
|
|
36
|
+
],
|
|
37
|
+
[appLanguageApi]
|
|
38
|
+
);
|
|
39
|
+
const columns = useMemo(
|
|
40
|
+
() => [
|
|
41
|
+
{ title: "Ref ID", field: "ref" },
|
|
42
|
+
{ title: "Key", field: "key" },
|
|
43
|
+
...showLanguages.map((lang) => ({
|
|
44
|
+
title: getLanguageDisplayName(lang),
|
|
45
|
+
field: lang
|
|
46
|
+
}))
|
|
47
|
+
],
|
|
48
|
+
[showLanguages]
|
|
49
|
+
);
|
|
50
|
+
const data = useMemo(() => {
|
|
51
|
+
const rows = [];
|
|
52
|
+
if (resources.en) {
|
|
53
|
+
for (const ref of Object.keys(resources.en)) {
|
|
54
|
+
for (const key of Object.keys(resources.en[ref])) {
|
|
55
|
+
rows.push(
|
|
56
|
+
showLanguages.reduce(
|
|
57
|
+
(row, lang) => {
|
|
58
|
+
row[lang] = getTranslation(resources, lang, ref, key);
|
|
59
|
+
return row;
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
ref,
|
|
63
|
+
key
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const otherLang of Object.keys(resources)) {
|
|
71
|
+
if (otherLang === "en") {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
for (const ref of Object.keys(resources[otherLang])) {
|
|
75
|
+
for (const key of Object.keys(resources[otherLang][ref])) {
|
|
76
|
+
const resourceLang = resources.en;
|
|
77
|
+
const resourceKey = resourceLang?.[ref];
|
|
78
|
+
if (typeof resourceKey === "object" && resourceKey?.[key]) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const existingRow = rows.find((r) => r.ref === ref && r.key === key);
|
|
82
|
+
if (existingRow) {
|
|
83
|
+
showLanguages.forEach((lang) => {
|
|
84
|
+
existingRow[lang] = getTranslation(resources, lang, ref, key);
|
|
85
|
+
});
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
rows.push(
|
|
89
|
+
showLanguages.reduce(
|
|
90
|
+
(row, lang) => {
|
|
91
|
+
row[lang] = getTranslation(resources, lang, ref, key);
|
|
92
|
+
return row;
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
ref,
|
|
96
|
+
key
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return rows;
|
|
104
|
+
}, [resources, showLanguages]);
|
|
105
|
+
return /* @__PURE__ */ jsx(
|
|
106
|
+
Table,
|
|
107
|
+
{
|
|
108
|
+
title: `Loaded translations (${data.length})`,
|
|
109
|
+
columns,
|
|
110
|
+
data,
|
|
111
|
+
options: {
|
|
112
|
+
pageSize: 10,
|
|
113
|
+
pageSizeOptions: [10, 25, 100]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { LoadedTranslationsTable };
|
|
120
|
+
//# sourceMappingURL=LoadedTranslationsTable.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadedTranslationsTable.esm.js","sources":["../../src/components/LoadedTranslationsTable.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Table } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n appLanguageApiRef,\n translationApiRef,\n} from '@backstage/core-plugin-api/alpha';\n\nimport type { i18n as I18n, Resource } from 'i18next';\nimport { useMemo } from 'react';\n\ninterface Row {\n ref: string;\n key: string;\n [lang: string]: string | undefined;\n}\n\n// From https://github.com/backstage/backstage/blob/89f191b72c154e3f0bde70548a7bccbb23af8de0/plugins/user-settings/src/components/General/UserSettingsLanguageToggle.tsx#L68\nconst getLanguageDisplayName = (language: string) => {\n try {\n const names = new Intl.DisplayNames([language], {\n type: 'language',\n });\n const languageDisplayName = names.of(language);\n if (languageDisplayName) {\n return `${languageDisplayName} (${language})`;\n }\n return language;\n } catch (err) {\n return language;\n }\n};\n\nconst getTranslation = (\n resources: Resource,\n lang: string,\n ref: string,\n key: string,\n) => {\n const resourceLang = resources[lang];\n const resourceKey = resourceLang?.[ref];\n const translation =\n typeof resourceKey === 'object' ? resourceKey?.[key] : undefined;\n return translation;\n};\n\nexport const LoadedTranslationsTable = () => {\n const appLanguageApi = useApi(appLanguageApiRef);\n const translationApi = useApi(translationApiRef);\n const i18n: I18n = (translationApi as any).getI18nInstance();\n\n const resources = i18n.store.data;\n\n // FIXME: the available languages are not yet loaded...\n const showLanguages = useMemo(\n () => [\n 'en',\n ...appLanguageApi\n .getAvailableLanguages()\n .languages.filter(lang => lang !== 'en'),\n ],\n [appLanguageApi],\n );\n\n const columns = useMemo(\n () => [\n { title: 'Ref ID', field: 'ref' },\n { title: 'Key', field: 'key' },\n ...showLanguages.map(lang => ({\n title: getLanguageDisplayName(lang),\n field: lang,\n })),\n ],\n [showLanguages],\n );\n\n const data = useMemo(() => {\n const rows: Row[] = [];\n\n // Iterate first over primary language english\n if (resources.en) {\n for (const ref of Object.keys(resources.en)) {\n for (const key of Object.keys(resources.en[ref])) {\n rows.push(\n showLanguages.reduce(\n (row, lang) => {\n row[lang] = getTranslation(resources, lang, ref, key);\n return row;\n },\n {\n ref,\n key,\n } as Row,\n ),\n );\n }\n }\n }\n\n // Check if other languages have additional keys\n for (const otherLang of Object.keys(resources)) {\n if (otherLang === 'en') {\n continue;\n }\n for (const ref of Object.keys(resources[otherLang])) {\n for (const key of Object.keys(resources[otherLang][ref])) {\n // if the key exists in english, then it was already added\n const resourceLang = resources.en;\n const resourceKey = resourceLang?.[ref];\n if (typeof resourceKey === 'object' && resourceKey?.[key]) {\n continue;\n }\n // Check if we already have a row for this ref/key combination\n // from another language. If yes, then we can skip this as well.\n const existingRow = rows.find(r => r.ref === ref && r.key === key);\n if (existingRow) {\n showLanguages.forEach(lang => {\n existingRow[lang] = getTranslation(resources, lang, ref, key);\n });\n continue;\n }\n // Otherwise add a new row and include all languages\n rows.push(\n showLanguages.reduce(\n (row, lang) => {\n row[lang] = getTranslation(resources, lang, ref, key);\n return row;\n },\n {\n ref,\n key,\n } as Row,\n ),\n );\n }\n }\n }\n\n return rows;\n }, [resources, showLanguages]);\n\n return (\n <Table\n title={`Loaded translations (${data.length})`}\n columns={columns}\n data={data}\n options={{\n pageSize: 10,\n pageSizeOptions: [10, 25, 100],\n }}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AAgCA,MAAM,sBAAA,GAAyB,CAAC,QAAA,KAAqB;AACnD,EAAA,IAAI;AACF,IAAA,MAAM,QAAQ,IAAI,IAAA,CAAK,YAAA,CAAa,CAAC,QAAQ,CAAA,EAAG;AAAA,MAC9C,IAAA,EAAM;AAAA,KACP,CAAA;AACD,IAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,EAAA,CAAG,QAAQ,CAAA;AAC7C,IAAA,IAAI,mBAAA,EAAqB;AACvB,MAAA,OAAO,CAAA,EAAG,mBAAmB,CAAA,EAAA,EAAK,QAAQ,CAAA,CAAA,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,QAAA;AAAA,EACT,SAAS,GAAA,EAAK;AACZ,IAAA,OAAO,QAAA;AAAA,EACT;AACF,CAAA;AAEA,MAAM,cAAA,GAAiB,CACrB,SAAA,EACA,IAAA,EACA,KACA,GAAA,KACG;AACH,EAAA,MAAM,YAAA,GAAe,UAAU,IAAI,CAAA;AACnC,EAAA,MAAM,WAAA,GAAc,eAAe,GAAG,CAAA;AACtC,EAAA,MAAM,cACJ,OAAO,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AK,IAAA;AAAA,YACH,aAAA,CAAc,MAAA;AAAA,cACZ,CAAC,KAAK,IAAA,KAAS;AACb,gBAAA,GAAA,CAAI,IAAI,CAAA,GAAI,cAAA,CAAe,SAAA,EAAW,IAAA,EAAM,KAAK,GAAG,CAAA;AACpD,gBAAA,OAAO,GAAA;AAAA,cACT,CAAA;AAAA,cACA;AAAA,gBACE,GAAA;AAAA,gBACA;AAAA;AACF;AACF,WACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,EAAG,CAAC,SAAA,EAAW,aAAa,CAAC,CAAA;AAE7B,EAAA,uBACE,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,KAAA,EAAO,CAAA,qBAAA,EAAwB,IAAA,CAAK,MAAM,CAAA,CAAA,CAAA;AAAA,MAC1C,OAAA;AAAA,MACA,IAAA;AAAA,MACA,OAAA,EAAS;AAAA,QACP,QAAA,EAAU,EAAA;AAAA,QACV,eAAA,EAAiB,CAAC,EAAA,EAAI,EAAA,EAAI,GAAG;AAAA;AAC/B;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Page, Header, Content } from '@backstage/core-components';
|
|
3
|
+
import { LanguageToggleCard } from './LanguageToggleCard.esm.js';
|
|
4
|
+
import { LoadedTranslationsTable } from './LoadedTranslationsTable.esm.js';
|
|
5
|
+
import { AppLanguageCard } from './AppLanguageCard.esm.js';
|
|
6
|
+
import { I18NextCard } from './I18NextCard.esm.js';
|
|
7
|
+
|
|
8
|
+
const TranslationsPage = () => {
|
|
9
|
+
return /* @__PURE__ */ jsxs(Page, { themeId: "tool", children: [
|
|
10
|
+
/* @__PURE__ */ jsx(Header, { title: "Translations" }),
|
|
11
|
+
/* @__PURE__ */ jsxs(Content, { children: [
|
|
12
|
+
/* @__PURE__ */ jsx(LanguageToggleCard, {}),
|
|
13
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
14
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
15
|
+
/* @__PURE__ */ jsx(LoadedTranslationsTable, {}),
|
|
16
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
17
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
18
|
+
/* @__PURE__ */ jsx(AppLanguageCard, {}),
|
|
19
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
20
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
21
|
+
/* @__PURE__ */ jsx(I18NextCard, {})
|
|
22
|
+
] })
|
|
23
|
+
] });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { TranslationsPage };
|
|
27
|
+
//# sourceMappingURL=TranslationsPage.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranslationsPage.esm.js","sources":["../../src/components/TranslationsPage.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Page, Header, Content } from '@backstage/core-components';\n\nimport { LanguageToggleCard } from './LanguageToggleCard';\nimport { LoadedTranslationsTable } from './LoadedTranslationsTable';\nimport { AppLanguageCard } from './AppLanguageCard';\nimport { I18NextCard } from './I18NextCard';\n\nexport const TranslationsPage = () => {\n return (\n <Page themeId=\"tool\">\n <Header title=\"Translations\" />\n <Content>\n <LanguageToggleCard />\n <br />\n <br />\n <LoadedTranslationsTable />\n <br />\n <br />\n <AppLanguageCard />\n <br />\n <br />\n <I18NextCard />\n </Content>\n </Page>\n );\n};\n"],"names":[],"mappings":";;;;;;;AAsBO,MAAM,mBAAmB,MAAM;AACpC,EAAA,uBACE,IAAA,CAAC,IAAA,EAAA,EAAK,OAAA,EAAQ,MAAA,EACZ,QAAA,EAAA;AAAA,oBAAA,GAAA,CAAC,MAAA,EAAA,EAAO,OAAM,cAAA,EAAe,CAAA;AAAA,yBAC5B,OAAA,EAAA,EACC,QAAA,EAAA;AAAA,sBAAA,GAAA,CAAC,kBAAA,EAAA,EAAmB,CAAA;AAAA,0BACnB,IAAA,EAAA,EAAG,CAAA;AAAA,0BACH,IAAA,EAAA,EAAG,CAAA;AAAA,0BACH,uBAAA,EAAA,EAAwB,CAAA;AAAA,0BACxB,IAAA,EAAA,EAAG,CAAA;AAAA,0BACH,IAAA,EAAA,EAAG,CAAA;AAAA,0BACH,eAAA,EAAA,EAAgB,CAAA;AAAA,0BAChB,IAAA,EAAA,EAAG,CAAA;AAAA,0BACH,IAAA,EAAA,EAAG,CAAA;AAAA,0BACH,WAAA,EAAA,EAAY;AAAA,KAAA,EACf;AAAA,GAAA,EACF,CAAA;AAEJ;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TranslationApi, AppLanguageApi, TranslationMessages, TranslationResource, TranslationRef, TranslationSnapshot } from '@backstage/core-plugin-api/alpha';
|
|
2
|
+
import { i18n } from 'i18next';
|
|
3
|
+
import { Observable } from '@backstage/types';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
|
|
6
|
+
|
|
7
|
+
/** @public */
|
|
8
|
+
interface I18nextTranslationApiOptions {
|
|
9
|
+
languageApi: AppLanguageApi;
|
|
10
|
+
resources?: Array<TranslationMessages | TranslationResource>;
|
|
11
|
+
}
|
|
12
|
+
/** @public */
|
|
13
|
+
declare class I18nextTranslationApi implements TranslationApi {
|
|
14
|
+
#private;
|
|
15
|
+
static create(options: I18nextTranslationApiOptions): I18nextTranslationApi;
|
|
16
|
+
private constructor();
|
|
17
|
+
getI18nInstance(): i18n;
|
|
18
|
+
getTranslation<TMessages extends {
|
|
19
|
+
[key in string]: string;
|
|
20
|
+
}>(translationRef: TranslationRef<string, TMessages>): TranslationSnapshot<TMessages>;
|
|
21
|
+
translation$<TMessages extends {
|
|
22
|
+
[key in string]: string;
|
|
23
|
+
}>(translationRef: TranslationRef<string, TMessages>): Observable<TranslationSnapshot<TMessages>>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
declare const translationsPlugin: _backstage_core_plugin_api.BackstagePlugin<{
|
|
30
|
+
root: _backstage_core_plugin_api.RouteRef<undefined>;
|
|
31
|
+
}, {}, {}>;
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
declare const TranslationsPage: () => react_jsx_runtime.JSX.Element;
|
|
36
|
+
|
|
37
|
+
export { I18nextTranslationApi, TranslationsPage, translationsPlugin };
|
|
38
|
+
export type { I18nextTranslationApiOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createPlugin, createRoutableExtension } from '@backstage/core-plugin-api';
|
|
2
|
+
import { rootRouteRef } from './routes.esm.js';
|
|
3
|
+
|
|
4
|
+
const translationsPlugin = createPlugin({
|
|
5
|
+
id: "translations",
|
|
6
|
+
routes: {
|
|
7
|
+
root: rootRouteRef
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
const TranslationsPage = translationsPlugin.provide(
|
|
11
|
+
createRoutableExtension({
|
|
12
|
+
name: "TranslationsPage",
|
|
13
|
+
component: () => import('./components/TranslationsPage.esm.js').then((m) => m.TranslationsPage),
|
|
14
|
+
mountPoint: rootRouteRef
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export { TranslationsPage, translationsPlugin };
|
|
19
|
+
//# sourceMappingURL=plugin.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n createPlugin,\n createRoutableExtension,\n} from '@backstage/core-plugin-api';\n\nimport { rootRouteRef } from './routes';\n\n/**\n * @public\n */\nexport const translationsPlugin = createPlugin({\n id: 'translations',\n routes: {\n root: rootRouteRef,\n },\n});\n\n/**\n * @public\n */\nexport const TranslationsPage = translationsPlugin.provide(\n createRoutableExtension({\n name: 'TranslationsPage',\n component: () =>\n import('./components/TranslationsPage').then(m => m.TranslationsPage),\n mountPoint: rootRouteRef,\n }),\n);\n"],"names":[],"mappings":";;;AAyBO,MAAM,qBAAqB,YAAA,CAAa;AAAA,EAC7C,EAAA,EAAI,cAAA;AAAA,EACJ,MAAA,EAAQ;AAAA,IACN,IAAA,EAAM;AAAA;AAEV,CAAC;AAKM,MAAM,mBAAmB,kBAAA,CAAmB,OAAA;AAAA,EACjD,uBAAA,CAAwB;AAAA,IACtB,IAAA,EAAM,kBAAA;AAAA,IACN,SAAA,EAAW,MACT,OAAO,sCAA+B,EAAE,IAAA,CAAK,CAAA,CAAA,KAAK,EAAE,gBAAgB,CAAA;AAAA,IACtE,UAAA,EAAY;AAAA,GACb;AACH;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.esm.js","sources":["../src/routes.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createRouteRef } from '@backstage/core-plugin-api';\n\nexport const rootRouteRef = createRouteRef({\n id: 'translations',\n});\n"],"names":[],"mappings":";;AAiBO,MAAM,eAAe,cAAA,CAAe;AAAA,EACzC,EAAA,EAAI;AACN,CAAC;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@red-hat-developer-hub/backstage-plugin-translations",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"main": "dist/index.esm.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"main": "dist/index.esm.js",
|
|
10
|
+
"types": "dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/redhat-developer/rhdh-plugins",
|
|
15
|
+
"directory": "workspaces/translations/plugins/translations"
|
|
16
|
+
},
|
|
17
|
+
"backstage": {
|
|
18
|
+
"role": "frontend-plugin",
|
|
19
|
+
"pluginId": "translations",
|
|
20
|
+
"pluginPackages": [
|
|
21
|
+
"@red-hat-developer-hub/backstage-plugin-translations"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "backstage-cli package start",
|
|
27
|
+
"build": "backstage-cli package build",
|
|
28
|
+
"lint": "backstage-cli package lint",
|
|
29
|
+
"test": "backstage-cli package test",
|
|
30
|
+
"clean": "backstage-cli package clean",
|
|
31
|
+
"prepack": "backstage-cli package prepack",
|
|
32
|
+
"postpack": "backstage-cli package postpack"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@backstage/core-components": "^0.17.2",
|
|
36
|
+
"@backstage/core-plugin-api": "^1.10.7",
|
|
37
|
+
"@backstage/plugin-user-settings": "^0.8.22",
|
|
38
|
+
"@backstage/theme": "^0.6.6",
|
|
39
|
+
"@backstage/types": "^1.2.1",
|
|
40
|
+
"i18next": "^22.4.15",
|
|
41
|
+
"zen-observable": "^0.10.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@backstage/cli": "^0.32.1",
|
|
48
|
+
"@backstage/core-app-api": "^1.17.0",
|
|
49
|
+
"@backstage/dev-utils": "^1.1.10",
|
|
50
|
+
"@backstage/test-utils": "^1.7.8",
|
|
51
|
+
"@testing-library/jest-dom": "^6.0.0",
|
|
52
|
+
"@testing-library/react": "^14.0.0",
|
|
53
|
+
"@testing-library/user-event": "^14.0.0",
|
|
54
|
+
"@types/zen-observable": "^0.8.7",
|
|
55
|
+
"msw": "^1.0.0",
|
|
56
|
+
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"dist"
|
|
60
|
+
],
|
|
61
|
+
"typesVersions": {
|
|
62
|
+
"*": {
|
|
63
|
+
"package.json": [
|
|
64
|
+
"package.json"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"module": "./dist/index.esm.js"
|
|
69
|
+
}
|