@forge/bridge 3.5.1-next.4 → 4.0.0-next.6
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 +22 -0
- package/out/i18n/index.d.ts +6 -0
- package/out/i18n/index.d.ts.map +1 -0
- package/out/i18n/index.js +50 -0
- package/out/index.d.ts +1 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -0
- package/out/types.d.ts +2 -1
- package/out/types.d.ts.map +1 -1
- package/out/view/getContext.d.ts.map +1 -1
- package/out/view/getContext.js +11 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @forge/bridge
|
|
2
2
|
|
|
3
|
+
## 4.0.0-next.6
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- a27f856: Ensure locale returned from getContext() is in the correct format and confirms the Forge Supported Locale Codes.
|
|
8
|
+
|
|
9
|
+
Additionally, add new APIs for Forge i18n support.
|
|
10
|
+
|
|
11
|
+
- `i18n.getTranslations` - Add i18n.getTranslations api to fetch i18n resources from Forge apps
|
|
12
|
+
- `i18n.createTranslationFunction` - Creates a translation function (i.e. `t`) to support content translation for Forge apps
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [c81fa57]
|
|
17
|
+
- @forge/i18n@0.0.1-next.10
|
|
18
|
+
|
|
19
|
+
## 3.5.1-next.5
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- @forge/i18n@0.0.1-next.9
|
|
24
|
+
|
|
3
25
|
## 3.5.1-next.4
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ForgeSupportedLocaleCode, type GetTranslationsOptions, type GetTranslationsResult } from '@forge/i18n';
|
|
2
|
+
export declare const resetTranslationsCache: () => void;
|
|
3
|
+
export declare const getTranslations: (locale?: ForgeSupportedLocaleCode | null, options?: GetTranslationsOptions) => Promise<GetTranslationsResult>;
|
|
4
|
+
export declare type TranslationFunction = (i18nKey: string, defaultValue?: string) => string;
|
|
5
|
+
export declare const createTranslationFunction: (locale?: ForgeSupportedLocaleCode | null) => Promise<TranslationFunction>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAM3B,MAAM,aAAa,CAAC;AAuBrB,eAAO,MAAM,sBAAsB,QAAO,IAEzC,CAAC;AAEF,eAAO,MAAM,eAAe,YAClB,wBAAwB,GAAG,IAAI,YAC9B,sBAAsB,KAG9B,QAAQ,qBAAqB,CAO/B,CAAC;AAUF,oBAAY,mBAAmB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AASrF,eAAO,MAAM,yBAAyB,YAC5B,wBAAwB,GAAG,IAAI,KACtC,QAAQ,mBAAmB,CAS7B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTranslationFunction = exports.getTranslations = exports.resetTranslationsCache = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const i18n_1 = require("@forge/i18n");
|
|
6
|
+
const view_1 = require("../view");
|
|
7
|
+
const frontendResourcesAccessor = {
|
|
8
|
+
getI18nInfoConfig: () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
+
const resp = yield fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${i18n_1.I18N_INFO_FILE_NAME}`);
|
|
10
|
+
if (!resp.ok) {
|
|
11
|
+
throw new Error('Failed to get i18n info config: ' + resp.statusText);
|
|
12
|
+
}
|
|
13
|
+
const info = (yield resp.json());
|
|
14
|
+
return info.config;
|
|
15
|
+
}),
|
|
16
|
+
getTranslationResource: (locale) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const resp = yield fetch(`./${i18n_1.I18N_BUNDLE_FOLDER_NAME}/${locale}.json`);
|
|
18
|
+
if (!resp.ok) {
|
|
19
|
+
throw new Error(`Failed to get translation resource for locale: ${locale}`);
|
|
20
|
+
}
|
|
21
|
+
return resp.json();
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
const translationsGetter = new i18n_1.TranslationsGetter(frontendResourcesAccessor);
|
|
25
|
+
const resetTranslationsCache = () => {
|
|
26
|
+
translationsGetter.reset();
|
|
27
|
+
};
|
|
28
|
+
exports.resetTranslationsCache = resetTranslationsCache;
|
|
29
|
+
const getTranslations = (locale = null, options = {
|
|
30
|
+
fallback: true
|
|
31
|
+
}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
let targetLocale = locale;
|
|
33
|
+
if (!targetLocale) {
|
|
34
|
+
const context = yield view_1.view.getContext();
|
|
35
|
+
targetLocale = context.locale;
|
|
36
|
+
}
|
|
37
|
+
return yield translationsGetter.getTranslations(targetLocale, options);
|
|
38
|
+
});
|
|
39
|
+
exports.getTranslations = getTranslations;
|
|
40
|
+
const createTranslationFunction = (locale = null) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
let targetLocale = locale;
|
|
42
|
+
if (!targetLocale) {
|
|
43
|
+
const context = yield view_1.view.getContext();
|
|
44
|
+
targetLocale = context.locale;
|
|
45
|
+
}
|
|
46
|
+
const translator = new i18n_1.Translator(targetLocale, translationsGetter);
|
|
47
|
+
yield translator.init();
|
|
48
|
+
return (i18nKey, defaultValue) => { var _a, _b; return (_b = (_a = translator.translate(i18nKey)) !== null && _a !== void 0 ? _a : defaultValue) !== null && _b !== void 0 ? _b : i18nKey; };
|
|
49
|
+
});
|
|
50
|
+
exports.createTranslationFunction = createTranslationFunction;
|
package/out/index.d.ts
CHANGED
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
|
package/out/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.i18n = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
tslib_1.__exportStar(require("./invoke"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./invoke-remote"), exports);
|
|
@@ -9,3 +10,4 @@ tslib_1.__exportStar(require("./modal"), exports);
|
|
|
9
10
|
tslib_1.__exportStar(require("./fetch"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./flag"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./events"), exports);
|
|
13
|
+
exports.i18n = tslib_1.__importStar(require("./i18n"));
|
package/out/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ForgeSupportedLocaleCode } from '@forge/i18n';
|
|
1
2
|
export declare type InvokePayload = {
|
|
2
3
|
[key in number | string]: any;
|
|
3
4
|
};
|
|
@@ -16,7 +17,7 @@ export interface FullContext {
|
|
|
16
17
|
extension: ExtensionData;
|
|
17
18
|
license?: LicenseDetails;
|
|
18
19
|
localId: string;
|
|
19
|
-
locale:
|
|
20
|
+
locale: ForgeSupportedLocaleCode;
|
|
20
21
|
moduleKey: string;
|
|
21
22
|
siteUrl: string;
|
|
22
23
|
timezone: string;
|
package/out/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa,GAAG;KACzB,GAAG,IAAI,MAAM,GAAG,MAAM,GAAG,GAAG;CAC9B,CAAC;AAEF,oBAAY,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;AAExD,oBAAY,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,YAAY,CAAC,CAAC;AAEhD,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,wBAAwB,EA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AAG;IACzB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../src/view/getContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../src/view/getContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAKvC,eAAO,MAAM,UAAU,QAAa,QAAQ,WAAW,CAStD,CAAC"}
|
package/out/view/getContext.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getContext = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const bridge_1 = require("../bridge");
|
|
6
|
+
const i18n_1 = require("@forge/i18n");
|
|
5
7
|
const callBridge = (0, bridge_1.getCallBridge)();
|
|
6
|
-
const getContext = () => {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const getContext = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
+
var _a;
|
|
10
|
+
const context = yield callBridge('getContext');
|
|
11
|
+
const locale = context === null || context === void 0 ? void 0 : context.locale;
|
|
12
|
+
if (locale) {
|
|
13
|
+
context.locale = (_a = (0, i18n_1.ensureLocale)(locale)) !== null && _a !== void 0 ? _a : locale;
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
});
|
|
9
17
|
exports.getContext = getContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/bridge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-next.6",
|
|
4
4
|
"description": "Forge bridge API for custom UI apps",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@types/history": "^4.7.11",
|
|
17
|
-
"@forge/i18n": "0.0.1-next.
|
|
17
|
+
"@forge/i18n": "0.0.1-next.10"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"history": "5.3.0",
|