Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization support #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

maximilianloy
Copy link

This adds the ability to localise the strings prepended with "_@"

Here is an example:

app-settings.json:

[{
  "title": "_@pref_notif_title",
  "description": "_@pref_notif_summary",
  "type": "radio",
  "key": "threshold",
  "default": "2",
  "items": [{
    "value": "1",
    "title": "_@always"
  }, {
    "value": "2",
    "title": "_@level_2"
  }]
}

Will generate e.g. for Android:

values/apppreferences.xml:

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string-array name="apppreferences_threshold">
        <item>@string/always</item>
        <item>@string/level_2</item>
    </string-array>
    <string-array name="apppreferences_thresholdValues">
        <item>1</item>
        <item>2</item>
    </string-array>
</resources>

xml/apppreferences.xml:

<?xml version='1.0' encoding='utf-8'?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <ListPreference android:defaultValue="2" android:entries="@array/apppreferences_threshold" android:entryValues="@array/apppreferences_thresholdValues" android:key="threshold" android:summary="@string/pref_notif_summary" android:title="@string/pref_notif_title" />
</PreferenceScreen>

Translations are stored in Settings.bundle/[locale].lproj/Root.strings and res/values/pref-strings.xml files which are copied (recursively) by the following script (not part of pull request) to the projects platform folders:
hooks/after_prepare/020_copy_res.js:

#!/usr/bin/env node
// Copy platform resource folders
'use strict';
var ncp = require('ncp');
ncp('resources/android/res', 'platforms/android/res', function(err) {
  if (err) {
    return console.error(err);
  }
});
ncp('resources/ios/Settings.bundle', 'platforms/ios/Settings.bundle', function(err) {
  if (err) {
    return console.error(err);
  }
});

@maximilianloy maximilianloy mentioned this pull request Jul 25, 2016
15 tasks
@pke
Copy link

pke commented Oct 24, 2016

Good one. I'd prefer to have the translations in a simple json and the plugin to write the entries to the platforms appropriate resources files as part of the prepare step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants