Skip to content

Commit

Permalink
Merge pull request #11 from transifex/improve-source-extraction
Browse files Browse the repository at this point in the history
Improve React CLI source extraction
  • Loading branch information
Nikos Vasileiou authored Jul 29, 2020
2 parents 0e4ae23 + 296cc5d commit a171fd9
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 46 deletions.
6 changes: 3 additions & 3 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions packages/cli/src/api/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ function extractPhrases(file, relativeFile, globalTags) {
let string;
const params = {};
_.each(elem.attributes, (attr) => {
if (attr.name.name === '_str') {
string = attr.value.value;
const property = attr.name && attr.name.name;
const value = attr.value && attr.value.value;
if (!property || !value) return;
if (property === '_str') {
string = value;
return;
}
if (_.isString(attr.value.value) || _.isNumber(attr.value.value)) {
params[attr.name.name] = attr.value.value;
if (_.isString(value) || _.isNumber(value)) {
params[property] = value;
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/fixtures/react.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function foo() {
_charlimit="10"
_comment="comment" />

<T _str="Text 2" />
<T _str="Text 3" />
<T _str="Text 2" _html/>
<T _str="Text 3" _html _inline />
<T _str="Text 4" />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/native/dist/browser.native.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/native/dist/browser.native.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/native/dist/node.native.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/native/dist/node.native.js.map

Large diffs are not rendered by default.

67 changes: 46 additions & 21 deletions packages/native/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"eslint-plugin-import": "^2.22.0",
"glob": "^7.1.6",
"mocha": "^8.0.1",
"nock": "^13.0.2",
"nock": "^13.0.3",
"nyc": "^15.1.0",
"source-map-support": "^0.5.19",
"webpack": "^4.43.0",
"webpack": "^4.44.0",
"webpack-cli": "^3.3.12"
},
"dependencies": {
Expand Down
16 changes: 6 additions & 10 deletions packages/native/src/TxNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
FETCHING_LOCALES, LOCALES_FETCHED, LOCALES_FETCH_FAILED,
LOCALE_CHANGED,
} from './events';
import { normalizeLocale } from './utils';

/**
* Native instance, combines functionality from
Expand Down Expand Up @@ -86,13 +85,10 @@ export default class TxNative {
return;
}

// normalize locale
const processedLocaleCode = normalizeLocale(localeCode);

// contact CDS
try {
sendEvent(FETCHING_TRANSLATIONS, processedLocaleCode, this);
const response = await axios.get(`${this.core.cdsHost}/content/${processedLocaleCode}`, {
sendEvent(FETCHING_TRANSLATIONS, localeCode, this);
const response = await axios.get(`${this.core.cdsHost}/content/${localeCode}`, {
headers: {
Authorization: `Bearer ${this.core.token}`,
},
Expand All @@ -106,14 +102,14 @@ export default class TxNative {
hashmap[key] = data.data[key].string;
}
});
this.core.cache.update(processedLocaleCode, hashmap);
sendEvent(TRANSLATIONS_FETCHED, processedLocaleCode, this);
this.core.cache.update(localeCode, hashmap);
sendEvent(TRANSLATIONS_FETCHED, localeCode, this);
} else {
sendEvent(TRANSLATIONS_FETCH_FAILED, processedLocaleCode, this);
sendEvent(TRANSLATIONS_FETCH_FAILED, localeCode, this);
throw new Error('Could not fetch translations');
}
} catch (err) {
sendEvent(TRANSLATIONS_FETCH_FAILED, processedLocaleCode, this);
sendEvent(TRANSLATIONS_FETCH_FAILED, localeCode, this);
throw err;
}
}
Expand Down

0 comments on commit a171fd9

Please sign in to comment.