This repository has been archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
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
1 parent
8dc073b
commit fe4e32e
Showing
16 changed files
with
283 additions
and
74 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
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
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
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
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
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 @@ | ||
{} |
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
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
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,40 @@ | ||
# Languages Files | ||
|
||
> This page is part of the [App Framework Documentation](../DOCUMENTATION.md) | ||
<br /> | ||
|
||
Languages files provide a simple way to make your app multi-lingual. | ||
|
||
## Storage | ||
|
||
Language files should be saved in folder *app/lang*. They should be JSON files with plain key:string pairs. | ||
|
||
Example `lang/de.json`: | ||
|
||
``` | ||
{ | ||
"emailSubject": "Greetings from Hamburg", | ||
"emailBody": "Hello {{username}}!" | ||
} | ||
``` | ||
|
||
After you added a new language file, the development server should be restarted. | ||
|
||
## Usage | ||
|
||
In templates: | ||
- `{{$lang('emailSubject')}}` | ||
- `{{$lang('emailBody', {username: 'Bugs Bunny'})` | ||
|
||
In scripts: | ||
- `this.$lang('emailSubject')` | ||
- `this.$lang('emailBody', {username: 'Bugs Bunny'})` | ||
|
||
## Default language | ||
|
||
To be configured, for example `"defaultLanguage": "en"`. This file is the master file to which all other language files are compared. If there are more keys than in the default language file, an error will be shown on any build command. | ||
|
||
## Default language fallback | ||
|
||
To be configured, by default `"defaultLanguageFallback": false`. If set to false, an error will be shown if any key is missing compared to the default language file on any build command. If set to true and a key is missing in a secondary language file, the default language is used. |
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
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
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,76 @@ | ||
// Purpose: Check language files, compare to default language file and sort each file by keys | ||
|
||
// Load modules | ||
const env = require('./env') | ||
const alert = require('./alert') | ||
const found = require('./found') | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const abs = require('path').resolve | ||
const rec = require('recursive-readdir-sync') | ||
const sort = require('sort-keys-recursive') | ||
|
||
// Define language folder | ||
const langFolder = abs(env.app, 'lang') | ||
|
||
// Check if default language file exists | ||
const defaultLangFile = abs(langFolder, env.cfg.defaultLanguage + '.json') | ||
if (!found(defaultLangFile)) { | ||
alert(`Default language file lang/${env.cfg.defaultLanguage}.json not found.`, 'error') | ||
} | ||
|
||
// Check if all language files are valid and sort each by key | ||
const langPatterns = {} | ||
try { | ||
const files = rec(langFolder) | ||
files.forEach((file) => { | ||
const patterns = fs.readJsonSync(file) | ||
const language = path.basename(file).slice(0, -5) | ||
langPatterns[language] = patterns | ||
fs.writeJsonSync(file, sort(patterns), { spaces: 2 }) | ||
}) | ||
} catch (err) { | ||
alert('Failed to read language files.', 'issue') | ||
} | ||
|
||
// Check all files if they have flat key:string pairs | ||
for (let lang in langPatterns) { | ||
let errors = 0 | ||
for (let key in langPatterns[lang]) { | ||
if (typeof langPatterns[lang][key] !== 'string') { | ||
errors++ | ||
} | ||
} | ||
if (errors > 0) { | ||
alert(`Language file lang/${lang}.json should contain plain key:string pairs.`, 'error') | ||
} | ||
} | ||
|
||
// Compare languages files to default language file | ||
// Loop all languages | ||
for (let lang in langPatterns) { | ||
// It's not the default language | ||
if (lang !== env.cfg.defaultLanguage) { | ||
const diffs = [] | ||
// Loop all items of the default language | ||
if (env.cfg.defaultLanguageFallback === false) { | ||
for (let key in langPatterns[env.cfg.defaultLanguage]) { | ||
// Missing items | ||
if (langPatterns[lang][key] === undefined) { | ||
diffs.push(`"${key}" is missing`) | ||
} | ||
} | ||
} | ||
// Loop all items of the second language | ||
for (let key in langPatterns[lang]) { | ||
// Too much items | ||
if (langPatterns[env.cfg.defaultLanguage][key] === undefined) { | ||
diffs.push(`"${key}" is too much`) | ||
} | ||
} | ||
// Differences found | ||
if (diffs.length > 0) { | ||
alert(`Language file lang/${lang}.json is different to the default one:\n- ` + diffs.join('\n- '), 'error') | ||
} | ||
} | ||
} |
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
Oops, something went wrong.