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

Adds YAML support #58

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ exports[`Test Fixtures unused-translations 1`] = `
👏 No missing translations were found!
"
`;

exports[`Test Fixtures yaml-translations 1`] = `
"[1/4] 🔍 Finding JS and HBS files...
[2/4] 🔍 Searching for translations keys in JS and HBS files...
[3/4] ⚙️ Checking for unused translations...
[4/4] ⚙️ Checking for missing translations...

👏 No unused translations were found!

👏 No missing translations were found!
"
`;
7 changes: 7 additions & 0 deletions fixtures/yaml-translations/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Controller from '@ember/controller';

export default Controller.extend({
foo: computed('intl.locale', function() {
return this.intl.t('js-translation');
}),
});
1 change: 1 addition & 0 deletions fixtures/yaml-translations/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{t "hbs-translation"}}
2 changes: 2 additions & 0 deletions fixtures/yaml-translations/translations/de.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hbs-translation: Lenkstage
js-translation: Affentheater
2 changes: 2 additions & 0 deletions fixtures/yaml-translations/translations/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hbs-translation: HBS!
js-translation: JS!
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const BabelParser = require('@babel/parser');
const traverse = require('@babel/traverse').default;
const Glimmer = require('@glimmer/syntax');
const Emblem = require('emblem').default;
const YAML = require('yaml');

async function run(rootDir, options = {}) {
let log = options.log || console.log;
Expand Down Expand Up @@ -89,7 +90,9 @@ async function findAppFiles(cwd) {
}

async function findTranslationFiles(cwd) {
return globby(['translations/**/*.json'], { cwd });
return globby(['translations/**/*.json', 'translations/**/*.yaml', 'translations/**/*.yml'], {
cwd,
});
}

async function analyzeFiles(cwd, files) {
Expand Down Expand Up @@ -197,8 +200,8 @@ async function analyzeTranslationFiles(cwd, files) {

for (let file of files) {
let content = fs.readFileSync(`${cwd}/${file}`, 'utf8');
let json = JSON.parse(content);
forEachTranslation(json, key => {
let translations = YAML.parse(content); // json is valid yaml
forEachTranslation(translations, key => {
if (!existingTranslationKeys.has(key)) {
existingTranslationKeys.set(key, new Set());
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"emblem": "^0.12.1",
"esm": "^3.2.25",
"globby": "^10.0.1",
"pkg-dir": "^4.2.0"
"pkg-dir": "^4.2.0",
"yaml": "^1.6.0"
},
"devDependencies": {
"eslint": "^6.2.2",
Expand Down