@capawesome/capacitor-app-language 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/CapawesomeCapacitorAppLanguage.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +269 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/AppLanguage.java +65 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/AppLanguagePlugin.java +136 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/classes/CustomExceptions.java +10 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/classes/options/SetLanguageOptions.java +33 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/classes/results/GetLanguageResult.java +25 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/applanguage/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +146 -0
- package/dist/esm/definitions.d.ts +73 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +30 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +33 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/AppLanguage.swift +36 -0
- package/ios/Plugin/AppLanguagePlugin.swift +71 -0
- package/ios/Plugin/Classes/Results/GetLanguageResult.swift +16 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.applanguage.classes.results;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.applanguage.interfaces.Result;
|
|
7
|
+
import org.json.JSONObject;
|
|
8
|
+
|
|
9
|
+
public class GetLanguageResult implements Result {
|
|
10
|
+
|
|
11
|
+
@Nullable
|
|
12
|
+
private final String languageTag;
|
|
13
|
+
|
|
14
|
+
public GetLanguageResult(@Nullable String languageTag) {
|
|
15
|
+
this.languageTag = languageTag;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
@NonNull
|
|
20
|
+
public JSObject toJSObject() {
|
|
21
|
+
JSObject result = new JSObject();
|
|
22
|
+
result.put("languageTag", languageTag == null ? JSONObject.NULL : languageTag);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "AppLanguagePlugin",
|
|
4
|
+
"slug": "applanguageplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "getLanguage",
|
|
10
|
+
"signature": "() => Promise<GetLanguageResult>",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "Promise<GetLanguageResult>",
|
|
13
|
+
"tags": [
|
|
14
|
+
{
|
|
15
|
+
"name": "since",
|
|
16
|
+
"text": "0.1.0"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"docs": "Get the app's current language override.\n\nThe language override is independent of the device language and only\naffects natively rendered strings (e.g. permission dialogs).",
|
|
20
|
+
"complexTypes": [
|
|
21
|
+
"GetLanguageResult"
|
|
22
|
+
],
|
|
23
|
+
"slug": "getlanguage"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "openSettings",
|
|
27
|
+
"signature": "() => Promise<void>",
|
|
28
|
+
"parameters": [],
|
|
29
|
+
"returns": "Promise<void>",
|
|
30
|
+
"tags": [
|
|
31
|
+
{
|
|
32
|
+
"name": "since",
|
|
33
|
+
"text": "0.1.0"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"docs": "Open the app's settings page in the system settings.\n\nOn iOS, this is where the user can change the app's language (the language\nrow is only shown if the app bundle provides more than one localization).",
|
|
37
|
+
"complexTypes": [],
|
|
38
|
+
"slug": "opensettings"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "resetLanguage",
|
|
42
|
+
"signature": "() => Promise<void>",
|
|
43
|
+
"parameters": [],
|
|
44
|
+
"returns": "Promise<void>",
|
|
45
|
+
"tags": [
|
|
46
|
+
{
|
|
47
|
+
"name": "since",
|
|
48
|
+
"text": "0.1.0"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"docs": "Reset the app's language override so the app follows the device language\nagain.\n\nResetting the language recreates the current activity, which reloads the\nweb view.\n\nOnly available on Android.",
|
|
52
|
+
"complexTypes": [],
|
|
53
|
+
"slug": "resetlanguage"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "setLanguage",
|
|
57
|
+
"signature": "(options: SetLanguageOptions) => Promise<void>",
|
|
58
|
+
"parameters": [
|
|
59
|
+
{
|
|
60
|
+
"name": "options",
|
|
61
|
+
"docs": "",
|
|
62
|
+
"type": "SetLanguageOptions"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"returns": "Promise<void>",
|
|
66
|
+
"tags": [
|
|
67
|
+
{
|
|
68
|
+
"name": "since",
|
|
69
|
+
"text": "0.1.0"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"docs": "Set the app's language override.\n\nSetting the language recreates the current activity, which reloads the\nweb view.\n\nOn iOS, the language can only be changed by the user in the system\nsettings (see the `openSettings(...)` method).\n\nOnly available on Android.",
|
|
73
|
+
"complexTypes": [
|
|
74
|
+
"SetLanguageOptions"
|
|
75
|
+
],
|
|
76
|
+
"slug": "setlanguage"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"properties": []
|
|
80
|
+
},
|
|
81
|
+
"interfaces": [
|
|
82
|
+
{
|
|
83
|
+
"name": "GetLanguageResult",
|
|
84
|
+
"slug": "getlanguageresult",
|
|
85
|
+
"docs": "",
|
|
86
|
+
"tags": [
|
|
87
|
+
{
|
|
88
|
+
"text": "0.1.0",
|
|
89
|
+
"name": "since"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"methods": [],
|
|
93
|
+
"properties": [
|
|
94
|
+
{
|
|
95
|
+
"name": "languageTag",
|
|
96
|
+
"tags": [
|
|
97
|
+
{
|
|
98
|
+
"text": "'de-DE'",
|
|
99
|
+
"name": "example"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"text": "0.1.0",
|
|
103
|
+
"name": "since"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"docs": "The BCP 47 language tag of the app's language override.\n\nReturns `null` if no override is set and the app follows the device\nlanguage.",
|
|
107
|
+
"complexTypes": [],
|
|
108
|
+
"type": "string | null"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "SetLanguageOptions",
|
|
114
|
+
"slug": "setlanguageoptions",
|
|
115
|
+
"docs": "",
|
|
116
|
+
"tags": [
|
|
117
|
+
{
|
|
118
|
+
"text": "0.1.0",
|
|
119
|
+
"name": "since"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"methods": [],
|
|
123
|
+
"properties": [
|
|
124
|
+
{
|
|
125
|
+
"name": "languageTag",
|
|
126
|
+
"tags": [
|
|
127
|
+
{
|
|
128
|
+
"text": "'de-DE'",
|
|
129
|
+
"name": "example"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"text": "0.1.0",
|
|
133
|
+
"name": "since"
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"docs": "The BCP 47 language tag to set as the app's language override.",
|
|
137
|
+
"complexTypes": [],
|
|
138
|
+
"type": "string"
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"enums": [],
|
|
144
|
+
"typeAliases": [],
|
|
145
|
+
"pluginConfigs": []
|
|
146
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface AppLanguagePlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Get the app's current language override.
|
|
4
|
+
*
|
|
5
|
+
* The language override is independent of the device language and only
|
|
6
|
+
* affects natively rendered strings (e.g. permission dialogs).
|
|
7
|
+
*
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
*/
|
|
10
|
+
getLanguage(): Promise<GetLanguageResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Open the app's settings page in the system settings.
|
|
13
|
+
*
|
|
14
|
+
* On iOS, this is where the user can change the app's language (the language
|
|
15
|
+
* row is only shown if the app bundle provides more than one localization).
|
|
16
|
+
*
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
*/
|
|
19
|
+
openSettings(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Reset the app's language override so the app follows the device language
|
|
22
|
+
* again.
|
|
23
|
+
*
|
|
24
|
+
* Resetting the language recreates the current activity, which reloads the
|
|
25
|
+
* web view.
|
|
26
|
+
*
|
|
27
|
+
* Only available on Android.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.1.0
|
|
30
|
+
*/
|
|
31
|
+
resetLanguage(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Set the app's language override.
|
|
34
|
+
*
|
|
35
|
+
* Setting the language recreates the current activity, which reloads the
|
|
36
|
+
* web view.
|
|
37
|
+
*
|
|
38
|
+
* On iOS, the language can only be changed by the user in the system
|
|
39
|
+
* settings (see the `openSettings(...)` method).
|
|
40
|
+
*
|
|
41
|
+
* Only available on Android.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
setLanguage(options: SetLanguageOptions): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
*/
|
|
50
|
+
export interface GetLanguageResult {
|
|
51
|
+
/**
|
|
52
|
+
* The BCP 47 language tag of the app's language override.
|
|
53
|
+
*
|
|
54
|
+
* Returns `null` if no override is set and the app follows the device
|
|
55
|
+
* language.
|
|
56
|
+
*
|
|
57
|
+
* @example 'de-DE'
|
|
58
|
+
* @since 0.1.0
|
|
59
|
+
*/
|
|
60
|
+
languageTag: string | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
*/
|
|
65
|
+
export interface SetLanguageOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The BCP 47 language tag to set as the app's language override.
|
|
68
|
+
*
|
|
69
|
+
* @example 'de-DE'
|
|
70
|
+
* @since 0.1.0
|
|
71
|
+
*/
|
|
72
|
+
languageTag: string;
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AppLanguagePlugin {\n /**\n * Get the app's current language override.\n *\n * The language override is independent of the device language and only\n * affects natively rendered strings (e.g. permission dialogs).\n *\n * @since 0.1.0\n */\n getLanguage(): Promise<GetLanguageResult>;\n /**\n * Open the app's settings page in the system settings.\n *\n * On iOS, this is where the user can change the app's language (the language\n * row is only shown if the app bundle provides more than one localization).\n *\n * @since 0.1.0\n */\n openSettings(): Promise<void>;\n /**\n * Reset the app's language override so the app follows the device language\n * again.\n *\n * Resetting the language recreates the current activity, which reloads the\n * web view.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n resetLanguage(): Promise<void>;\n /**\n * Set the app's language override.\n *\n * Setting the language recreates the current activity, which reloads the\n * web view.\n *\n * On iOS, the language can only be changed by the user in the system\n * settings (see the `openSettings(...)` method).\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n setLanguage(options: SetLanguageOptions): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetLanguageResult {\n /**\n * The BCP 47 language tag of the app's language override.\n *\n * Returns `null` if no override is set and the app follows the device\n * language.\n *\n * @example 'de-DE'\n * @since 0.1.0\n */\n languageTag: string | null;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface SetLanguageOptions {\n /**\n * The BCP 47 language tag to set as the app's language override.\n *\n * @example 'de-DE'\n * @since 0.1.0\n */\n languageTag: string;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const AppLanguage = registerPlugin('AppLanguage', {
|
|
3
|
+
web: () => import('./web').then(m => new m.AppLanguageWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { AppLanguage };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,WAAW,GAAG,cAAc,CAAoB,aAAa,EAAE;IACnE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC7D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { AppLanguagePlugin } from './definitions';\n\nconst AppLanguage = registerPlugin<AppLanguagePlugin>('AppLanguage', {\n web: () => import('./web').then(m => new m.AppLanguageWeb()),\n});\n\nexport * from './definitions';\nexport { AppLanguage };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { AppLanguagePlugin, GetLanguageResult, SetLanguageOptions } from './definitions';
|
|
3
|
+
export declare class AppLanguageWeb extends WebPlugin implements AppLanguagePlugin {
|
|
4
|
+
getLanguage(): Promise<GetLanguageResult>;
|
|
5
|
+
openSettings(): Promise<void>;
|
|
6
|
+
resetLanguage(): Promise<void>;
|
|
7
|
+
setLanguage(_options: SetLanguageOptions): Promise<void>;
|
|
8
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class AppLanguageWeb extends WebPlugin {
|
|
3
|
+
async getLanguage() {
|
|
4
|
+
throw this.unimplemented('Not implemented on web.');
|
|
5
|
+
}
|
|
6
|
+
async openSettings() {
|
|
7
|
+
throw this.unimplemented('Not implemented on web.');
|
|
8
|
+
}
|
|
9
|
+
async resetLanguage() {
|
|
10
|
+
throw this.unimplemented('Not implemented on web.');
|
|
11
|
+
}
|
|
12
|
+
async setLanguage(_options) {
|
|
13
|
+
throw this.unimplemented('Not implemented on web.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC3C,KAAK,CAAC,WAAW;QACf,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,QAA4B;QAC5C,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AppLanguagePlugin,\n GetLanguageResult,\n SetLanguageOptions,\n} from './definitions';\n\nexport class AppLanguageWeb extends WebPlugin implements AppLanguagePlugin {\n async getLanguage(): Promise<GetLanguageResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async openSettings(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async resetLanguage(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async setLanguage(_options: SetLanguageOptions): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const AppLanguage = core.registerPlugin('AppLanguage', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AppLanguageWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class AppLanguageWeb extends core.WebPlugin {
|
|
10
|
+
async getLanguage() {
|
|
11
|
+
throw this.unimplemented('Not implemented on web.');
|
|
12
|
+
}
|
|
13
|
+
async openSettings() {
|
|
14
|
+
throw this.unimplemented('Not implemented on web.');
|
|
15
|
+
}
|
|
16
|
+
async resetLanguage() {
|
|
17
|
+
throw this.unimplemented('Not implemented on web.');
|
|
18
|
+
}
|
|
19
|
+
async setLanguage(_options) {
|
|
20
|
+
throw this.unimplemented('Not implemented on web.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
25
|
+
__proto__: null,
|
|
26
|
+
AppLanguageWeb: AppLanguageWeb
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
exports.AppLanguage = AppLanguage;
|
|
30
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AppLanguage = registerPlugin('AppLanguage', {\n web: () => import('./web').then(m => new m.AppLanguageWeb()),\n});\nexport * from './definitions';\nexport { AppLanguage };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class AppLanguageWeb extends WebPlugin {\n async getLanguage() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openSettings() {\n throw this.unimplemented('Not implemented on web.');\n }\n async resetLanguage() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setLanguage(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAChE,CAAC;;ACFM,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,QAAQ,EAAE;AAChC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var capacitorAppLanguage = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const AppLanguage = core.registerPlugin('AppLanguage', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AppLanguageWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class AppLanguageWeb extends core.WebPlugin {
|
|
9
|
+
async getLanguage() {
|
|
10
|
+
throw this.unimplemented('Not implemented on web.');
|
|
11
|
+
}
|
|
12
|
+
async openSettings() {
|
|
13
|
+
throw this.unimplemented('Not implemented on web.');
|
|
14
|
+
}
|
|
15
|
+
async resetLanguage() {
|
|
16
|
+
throw this.unimplemented('Not implemented on web.');
|
|
17
|
+
}
|
|
18
|
+
async setLanguage(_options) {
|
|
19
|
+
throw this.unimplemented('Not implemented on web.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
24
|
+
__proto__: null,
|
|
25
|
+
AppLanguageWeb: AppLanguageWeb
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
exports.AppLanguage = AppLanguage;
|
|
29
|
+
|
|
30
|
+
return exports;
|
|
31
|
+
|
|
32
|
+
})({}, capacitorExports);
|
|
33
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AppLanguage = registerPlugin('AppLanguage', {\n web: () => import('./web').then(m => new m.AppLanguageWeb()),\n});\nexport * from './definitions';\nexport { AppLanguage };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class AppLanguageWeb extends WebPlugin {\n async getLanguage() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openSettings() {\n throw this.unimplemented('Not implemented on web.');\n }\n async resetLanguage() {\n throw this.unimplemented('Not implemented on web.');\n }\n async setLanguage(_options) {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;IAChE,CAAC;;ICFM,MAAM,cAAc,SAASC,cAAS,CAAC;IAC9C,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,QAAQ,EAAE;IAChC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc public class AppLanguage: NSObject {
|
|
5
|
+
private let plugin: AppLanguagePlugin
|
|
6
|
+
|
|
7
|
+
init(plugin: AppLanguagePlugin) {
|
|
8
|
+
self.plugin = plugin
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func getLanguage(completion: @escaping (GetLanguageResult?, Error?) -> Void) {
|
|
12
|
+
let languageTag = resolveLanguageOverride()
|
|
13
|
+
completion(GetLanguageResult(languageTag: languageTag), nil)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@objc public func openSettings(completion: @escaping (Error?) -> Void) {
|
|
17
|
+
guard let url = URL(string: UIApplication.openSettingsURLString) else {
|
|
18
|
+
completion(nil)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
DispatchQueue.main.async {
|
|
22
|
+
UIApplication.shared.open(url, options: [:]) { _ in
|
|
23
|
+
completion(nil)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private func resolveLanguageOverride() -> String? {
|
|
29
|
+
guard let bundleIdentifier = Bundle.main.bundleIdentifier,
|
|
30
|
+
let domain = UserDefaults.standard.persistentDomain(forName: bundleIdentifier),
|
|
31
|
+
let languages = domain["AppleLanguages"] as? [String] else {
|
|
32
|
+
return nil
|
|
33
|
+
}
|
|
34
|
+
return languages.first
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(AppLanguagePlugin)
|
|
5
|
+
public class AppLanguagePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "AppLanguagePlugin"
|
|
7
|
+
public let jsName = "AppLanguage"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "getLanguage", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "openSettings", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "resetLanguage", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "setLanguage", returnType: CAPPluginReturnPromise)
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
public static let tag = "AppLanguagePlugin"
|
|
16
|
+
|
|
17
|
+
private var implementation: AppLanguage?
|
|
18
|
+
|
|
19
|
+
override public func load() {
|
|
20
|
+
self.implementation = AppLanguage(plugin: self)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@objc func getLanguage(_ call: CAPPluginCall) {
|
|
24
|
+
implementation?.getLanguage { result, error in
|
|
25
|
+
if let error = error {
|
|
26
|
+
self.rejectCall(call, error)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
self.resolveCall(call, result)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@objc func openSettings(_ call: CAPPluginCall) {
|
|
34
|
+
implementation?.openSettings { error in
|
|
35
|
+
if let error = error {
|
|
36
|
+
self.rejectCall(call, error)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
self.resolveCall(call)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@objc func resetLanguage(_ call: CAPPluginCall) {
|
|
44
|
+
rejectCallAsUnimplemented(call)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@objc func setLanguage(_ call: CAPPluginCall) {
|
|
48
|
+
rejectCallAsUnimplemented(call)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
52
|
+
CAPLog.print("[", AppLanguagePlugin.tag, "] ", error)
|
|
53
|
+
call.reject(error.localizedDescription)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private func rejectCallAsUnimplemented(_ call: CAPPluginCall) {
|
|
57
|
+
call.unimplemented("This method is not available on this platform.")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private func resolveCall(_ call: CAPPluginCall) {
|
|
61
|
+
call.resolve()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
65
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
66
|
+
call.resolve(result)
|
|
67
|
+
} else {
|
|
68
|
+
call.resolve()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class GetLanguageResult: NSObject, Result {
|
|
5
|
+
let languageTag: String?
|
|
6
|
+
|
|
7
|
+
init(languageTag: String?) {
|
|
8
|
+
self.languageTag = languageTag
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@objc public func toJSObject() -> AnyObject {
|
|
12
|
+
var result = JSObject()
|
|
13
|
+
result["languageTag"] = languageTag == nil ? NSNull() : languageTag
|
|
14
|
+
return result as AnyObject
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-app-language",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Capacitor plugin to manage the app's language override.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorAppLanguage.podspec",
|
|
15
|
+
"Package.swift"
|
|
16
|
+
],
|
|
17
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/capawesome-team/capacitor-plugins/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/capawesome-team/"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "opencollective",
|
|
33
|
+
"url": "https://opencollective.com/capawesome"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://capawesome.io/docs/plugins/app-language/",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
44
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
45
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
46
|
+
"verify:web": "npm run build",
|
|
47
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
48
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
49
|
+
"eslint": "eslint . --ext ts",
|
|
50
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
51
|
+
"swiftlint": "node-swiftlint",
|
|
52
|
+
"docgen": "docgen --api AppLanguagePlugin --output-readme README.md --output-json dist/docs.json",
|
|
53
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
54
|
+
"clean": "rimraf ./dist",
|
|
55
|
+
"watch": "tsc --watch",
|
|
56
|
+
"ios:pod:install": "cd ios && pod install --repo-update && cd ..",
|
|
57
|
+
"ios:spm:install": "cd ios && swift package resolve && cd ..",
|
|
58
|
+
"prepublishOnly": "npm run build"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@capacitor/android": "8.0.0",
|
|
62
|
+
"@capacitor/cli": "8.0.0",
|
|
63
|
+
"@capacitor/core": "8.0.0",
|
|
64
|
+
"@capacitor/docgen": "0.3.1",
|
|
65
|
+
"@capacitor/ios": "8.0.0",
|
|
66
|
+
"@ionic/eslint-config": "0.4.0",
|
|
67
|
+
"eslint": "8.57.0",
|
|
68
|
+
"prettier-plugin-java": "2.6.7",
|
|
69
|
+
"rimraf": "6.1.2",
|
|
70
|
+
"rollup": "4.53.3",
|
|
71
|
+
"swiftlint": "2.0.0",
|
|
72
|
+
"typescript": "5.9.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@capacitor/core": ">=8.0.0"
|
|
76
|
+
},
|
|
77
|
+
"eslintConfig": {
|
|
78
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
79
|
+
},
|
|
80
|
+
"capacitor": {
|
|
81
|
+
"ios": {
|
|
82
|
+
"src": "ios"
|
|
83
|
+
},
|
|
84
|
+
"android": {
|
|
85
|
+
"src": "android"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|