Skip to content

Commit 7c62479

Browse files
authored
Merge pull request #58 from Duder-onomy/add-yaml-support
Adds YAML support
2 parents 816ff43 + 0563e0d commit 7c62479

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

__snapshots__/test.js.snap

+12
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,15 @@ exports[`Test Fixtures unused-translations 1`] = `
6767
👏 No missing translations were found!
6868
"
6969
`;
70+
71+
exports[`Test Fixtures yaml-translations 1`] = `
72+
"[1/4] 🔍 Finding JS and HBS files...
73+
[2/4] 🔍 Searching for translations keys in JS and HBS files...
74+
[3/4] ⚙️ Checking for unused translations...
75+
[4/4] ⚙️ Checking for missing translations...
76+
77+
👏 No unused translations were found!
78+
79+
👏 No missing translations were found!
80+
"
81+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Controller from '@ember/controller';
2+
3+
export default Controller.extend({
4+
foo: computed('intl.locale', function() {
5+
return this.intl.t('js-translation');
6+
}),
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{t "hbs-translation"}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hbs-translation: Lenkstage
2+
js-translation: Affentheater
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hbs-translation: HBS!
2+
js-translation: JS!

index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const BabelParser = require('@babel/parser');
99
const traverse = require('@babel/traverse').default;
1010
const Glimmer = require('@glimmer/syntax');
1111
const Emblem = require('emblem').default;
12+
const YAML = require('yaml');
1213

1314
async function run(rootDir, options = {}) {
1415
let log = options.log || console.log;
@@ -93,7 +94,9 @@ async function findAppFiles(cwd) {
9394
}
9495

9596
async function findTranslationFiles(cwd) {
96-
return globby(['translations/**/*.json'], { cwd });
97+
return globby(['translations/**/*.json', 'translations/**/*.yaml', 'translations/**/*.yml'], {
98+
cwd,
99+
});
97100
}
98101

99102
async function analyzeFiles(cwd, files) {
@@ -201,8 +204,8 @@ async function analyzeTranslationFiles(cwd, files) {
201204

202205
for (let file of files) {
203206
let content = fs.readFileSync(`${cwd}/${file}`, 'utf8');
204-
let json = JSON.parse(content);
205-
forEachTranslation(json, key => {
207+
let translations = YAML.parse(content); // json is valid yaml
208+
forEachTranslation(translations, key => {
206209
if (!existingTranslationKeys.has(key)) {
207210
existingTranslationKeys.set(key, new Set());
208211
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"emblem": "^0.12.1",
2727
"esm": "^3.2.25",
2828
"globby": "^10.0.1",
29-
"pkg-dir": "^4.2.0"
29+
"pkg-dir": "^4.2.0",
30+
"yaml": "^1.6.0"
3031
},
3132
"devDependencies": {
3233
"eslint": "^6.2.2",

0 commit comments

Comments
 (0)