-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 67628dd
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Specifies intentionally untracked files to ignore when using Git | ||
# http://git-scm.com/docs/gitignore | ||
|
||
node_modules/ | ||
platforms/ | ||
plugins/ | ||
www/lib/* | ||
resources/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## Supported languages iOS Apache Cordova | ||
|
||
**Cordova / PhoneGap Plugin that exposes supported languages to the App Store (iTunes).** | ||
|
||
On iOS, Cordova declares (just) english as supported language. Since most of the i18n solutions that developers use for their translation/internazionalizations support are javascript based there is no way to say to app store that anoter language is also supported. You need to explicitly declare those languages within the `info.plist` file. | ||
|
||
Since I'm lazy I prefer letting a plugin do this job (avoiding the need to re-edit the file everytime I do a fresh build from the cordova cli). Hope you find it useful as well. | ||
|
||
## Install | ||
|
||
### Latest published version on npm (with Cordova CLI >= 5.0.0) | ||
|
||
``` | ||
cordova plugin add cordova-plugin-ios-localized-strings --variable MAIN_LANGUAGE=English --variable ADDITIONAL_LANGUAGES=it,fr,de | ||
``` | ||
|
||
### Latest version from GitHub | ||
|
||
``` | ||
cordova plugin add https://github.com/enricodeleo/cordova-plugin-ios-localized-strings.git --variable MAIN_LANGUAGE=English --variable ADDITIONAL_LANGUAGES=it,fr,de | ||
``` | ||
|
||
## Platforms | ||
|
||
Applies to iOS only. | ||
|
||
## Bonus | ||
|
||
For ionic/angular v1.x based projects I really like [gabegorelick/gulp-angular-gettext](https://github.com/gabegorelick/gulp-angular-gettext). | ||
|
||
## License | ||
|
||
[MIT License](http://ilee.mit-license.org) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "cordova-plugin-ios-localized-strings", | ||
"version": "1.0.0", | ||
"author": "Enrico Deleo <hello@enricodeleo.com> (http://enricodeleo.com/)", | ||
"description": "Cordova / PhoneGap Plugin that exposes supported languages to the App Store (iTunes).", | ||
"cordova": { | ||
"id": "cordova-plugin-ios-localized-strings", | ||
"platforms": [ | ||
"ios" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/enricodeleo/cordova-plugin-ios-localized-strings.git" | ||
}, | ||
"keywords": [ | ||
"cordova", | ||
"ios", | ||
"app", | ||
"languages", | ||
"i18n", | ||
"appstore", | ||
"itunes", | ||
"strings", | ||
"ecosystem:cordova", | ||
"cordova-ios" | ||
], | ||
"engines": [ | ||
{ | ||
"name": "cordova", | ||
"version": ">=3.0.0" | ||
} | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/enricodeleo/cordova-plugin-ios-localized-strings/issues" | ||
}, | ||
"homepage": "https://github.com/enricodeleo/cordova-plugin-ios-localized-strings#readme", | ||
"devDependencies": { | ||
"plist": "^2.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<plugin id="cordova-plugin-ios-localized-strings" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0"> | ||
<name>Cordova iOS Localized Strings</name> | ||
<author>Enrico Deleo (http://enricodeleo.com/)</author> | ||
<description>Cordova / PhoneGap Plugin that declares supported languages for App Store (iTunes).</description> | ||
<keywords>cordova, ios, app, localization, strings, locale, internazionalization, i18n</keywords> | ||
<license>MIT</license> | ||
<engines> | ||
<engine name="cordova" version=">=3.0.0"/> | ||
</engines> | ||
|
||
<platform name="ios"> | ||
|
||
<preference name="MAIN_LANGUAGE" /> | ||
<preference name="ADDITIONAL_LANGUAGES" /> | ||
|
||
<config-file target="config.xml" parent="/*"> | ||
<preference name="MAIN_LANGUAGE" value="$MAIN_LANGUAGE"/> | ||
<preference name="ADDITIONAL_LANGUAGES" value="$ADDITIONAL_LANGUAGES"/> | ||
</config-file> | ||
|
||
<hook type="after_prepare" src="scripts/add_supported_languages.js" /> | ||
</platform> | ||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
// Add supported languages for App Store (iTunes) | ||
// v1.0.0 | ||
// Automatically adds supported languages to your iOS app | ||
// within the info.plist file after the `prepare` command. | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const plist = require('plist'); | ||
|
||
module.exports = context => { | ||
const ConfigParser = context.requireCordovaModule('cordova-common').ConfigParser; | ||
|
||
return new Promise((resolve, reject) => { | ||
let mainConfig = new ConfigParser(path.resolve(context.opts.projectRoot, 'config.xml')); | ||
let name = mainConfig.name(); | ||
let config = new ConfigParser(path.resolve(context.opts.projectRoot, 'platforms', 'ios', name, 'config.xml')); | ||
let MAIN_LANGUAGE = config.getGlobalPreference('MAIN_LANGUAGE'); | ||
let ADDITIONAL_LANGUAGES = config.getGlobalPreference('ADDITIONAL_LANGUAGES'); | ||
let plistPath = path.join(context.opts.projectRoot, 'platforms', 'ios', name, `${name}-Info.plist`); | ||
|
||
fs.readFile(plistPath, 'utf-8', (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
let infoPlist = plist.parse(data); | ||
|
||
process.stdout.write('[iOS] Setting main language to: ' + MAIN_LANGUAGE + '\n'); | ||
infoPlist.CFBundleDevelopmentRegion = MAIN_LANGUAGE; | ||
|
||
if ( ADDITIONAL_LANGUAGES ) { | ||
process.stdout.write('[iOS] Setting also additional languagees to: ' + ADDITIONAL_LANGUAGES.split(',') + '\n'); | ||
infoPlist.CFBundleLocalizations = ADDITIONAL_LANGUAGES.split(','); | ||
} | ||
|
||
fs.writeFile(plistPath, plist.build(infoPlist), err => { | ||
if (err) { | ||
return reject(); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}; |