@capawesome/capacitor-app-language 0.0.1 → 0.1.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @capawesome/capacitor-app-language
1
+ # Capacitor App Language Plugin
2
2
 
3
3
  Capacitor plugin to manage the app's own language override, independent of the device language.
4
4
 
@@ -16,13 +16,18 @@ Capacitor plugin to manage the app's own language override, independent of the d
16
16
  - ⚙️ **Settings**: Deep-link to the app's system settings page where the user can change the app language.
17
17
  - 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
18
18
  - 🔁 **Up-to-date**: Always supports the latest Capacitor version.
19
- - 🔗 **Compatibility**: Works alongside the [Localization](https://capawesome.io/plugins/localization/) plugin, which reads the user's localization preferences.
19
+ - 🤝 **Compatibility**: Works alongside the [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin, which reads the user's localization preferences.
20
20
 
21
21
  Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
22
22
 
23
- ## Newsletter
23
+ ## Use Cases
24
24
 
25
- Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
25
+ The App Language plugin is typically used whenever an app offers its own language selection, for example:
26
+
27
+ - **In-app language switcher**: Let users pick the app language from a settings screen instead of changing the device language (Android).
28
+ - **Consistent native dialogs**: Make sure natively rendered strings like permission dialogs and notifications match the language of your web UI.
29
+ - **Settings deep link**: Guide iOS users to the app's system settings page, where they can change the app language.
30
+ - **System default option**: Offer a "system default" entry that clears the override so the app follows the device language again (Android).
26
31
 
27
32
  ## Compatibility
28
33
 
@@ -117,6 +122,12 @@ No configuration required for this plugin.
117
122
 
118
123
  ## Usage
119
124
 
125
+ The following examples show how to get, set, and reset the app language override and open the app's settings page.
126
+
127
+ ### Get the current language override
128
+
129
+ Read the BCP 47 language tag of the app's current language override. Returns `null` if no override is set and the app follows the device language:
130
+
120
131
  ```typescript
121
132
  import { AppLanguage } from '@capawesome/capacitor-app-language';
122
133
 
@@ -124,14 +135,38 @@ const getLanguage = async () => {
124
135
  const { languageTag } = await AppLanguage.getLanguage();
125
136
  return languageTag;
126
137
  };
138
+ ```
139
+
140
+ ### Set the app language
141
+
142
+ Set the app's language override, independent of the device language. Note that this recreates the current activity, which reloads the web view. Only available on Android:
143
+
144
+ ```typescript
145
+ import { AppLanguage } from '@capawesome/capacitor-app-language';
127
146
 
128
147
  const setLanguage = async () => {
129
148
  await AppLanguage.setLanguage({ languageTag: 'de-DE' });
130
149
  };
150
+ ```
151
+
152
+ ### Reset the language override
153
+
154
+ Clear the override so the app follows the device language again. Only available on Android:
155
+
156
+ ```typescript
157
+ import { AppLanguage } from '@capawesome/capacitor-app-language';
131
158
 
132
159
  const resetLanguage = async () => {
133
160
  await AppLanguage.resetLanguage();
134
161
  };
162
+ ```
163
+
164
+ ### Open the app's settings page
165
+
166
+ Deep-link the user to the app's page in the system settings. On iOS, this is where the user can change the app language:
167
+
168
+ ```typescript
169
+ import { AppLanguage } from '@capawesome/capacitor-app-language';
135
170
 
136
171
  const openSettings = async () => {
137
172
  await AppLanguage.openSettings();
@@ -260,6 +295,45 @@ Setting the app language programmatically is only supported on Android. On iOS,
260
295
  | `resetLanguage()` | ✅ | ❌ Unimplemented | ❌ Unimplemented |
261
296
  | `openSettings()` | ✅ | ✅ | ❌ Unimplemented |
262
297
 
298
+ ## FAQ
299
+
300
+ ### Why can't I set the app language programmatically on iOS?
301
+
302
+ On iOS, the app language can only be changed by the user in the system settings, so the `setLanguage(...)` and `resetLanguage(...)` methods are not available there. Use `openSettings()` to deep-link the user to the app's settings page, where the language can be changed.
303
+
304
+ ### Does this plugin translate my web UI?
305
+
306
+ No. The language override only affects natively rendered strings, such as permission dialogs, notifications, or plugin-presented sheets. The language of your web UI should be handled by your app's i18n library.
307
+
308
+ ### Why is the language row not shown in the iOS system settings?
309
+
310
+ The per-app language row only appears if the app bundle provides more than one localization. Declare the supported localizations under the `CFBundleLocalizations` key in your app's `Info.plist`, as described in the [Installation](#installation) section.
311
+
312
+ ### Why does my app reload after calling `setLanguage`?
313
+
314
+ Setting or resetting the language recreates the current activity on Android, which reloads the web view. This is expected behavior and cannot be avoided.
315
+
316
+ ### How does the selected language persist across app restarts on Android?
317
+
318
+ On Android 13 and above, the override is integrated with the system settings via a `locales_config.xml` file. On Android 12 and below, you need to add the `AppLocalesMetadataHolderService` service to your `AndroidManifest.xml` to persist the selected language, as described in the [Installation](#installation) section.
319
+
320
+ ### How is this plugin different from the Localization plugin?
321
+
322
+ The [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin reads the user's localization preferences, such as preferred locales, time zone, and regional formatting settings. The App Language plugin manages the app's own language override, independent of the device language. The two plugins work well together.
323
+
324
+ ### Can I use this plugin with Ionic, React, Vue or Angular?
325
+
326
+ Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
327
+
328
+ ## Related Plugins
329
+
330
+ - [Localization](https://capawesome.io/docs/sdks/capacitor/localization/): Read the user's localization preferences, such as preferred locales, time zone, and regional formatting settings.
331
+ - [Settings Launcher](https://capawesome.io/docs/sdks/capacitor/settings-launcher/): Open native settings screens.
332
+
333
+ ## Newsletter
334
+
335
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
336
+
263
337
  ## Changelog
264
338
 
265
339
  See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/app-language/CHANGELOG.md).
@@ -30,7 +30,7 @@ android {
30
30
  buildTypes {
31
31
  release {
32
32
  minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
34
34
  }
35
35
  }
36
36
  lintOptions {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-app-language",
3
- "version": "0.0.1",
4
- "description": "Capacitor plugin to manage the app's language override.",
3
+ "version": "0.1.1",
4
+ "description": "Capacitor plugin to manage the app's language override on Android and iOS.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -33,11 +33,19 @@
33
33
  "url": "https://opencollective.com/capawesome"
34
34
  }
35
35
  ],
36
- "homepage": "https://capawesome.io/docs/plugins/app-language/",
36
+ "homepage": "https://capawesome.io/docs/sdks/capacitor/app-language/",
37
37
  "keywords": [
38
38
  "capacitor",
39
39
  "plugin",
40
- "native"
40
+ "native",
41
+ "capacitor-plugin",
42
+ "app language",
43
+ "language override",
44
+ "per-app language",
45
+ "locale",
46
+ "i18n",
47
+ "localization",
48
+ "change app language"
41
49
  ],
42
50
  "scripts": {
43
51
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",