Skip to content
Open
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
14 changes: 14 additions & 0 deletions src/server/__tests__/collectReactIntlTranslations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@ describe('collectReactIntlTranslations', () => {
});
expect(result).toEqual({ reactIntlId3: 'Hello {NAME}!' });
});

it('should include all keys with React Intl IDs, for the original lang', () => {
const result = collectReactIntlTranslations({
originalLang: 'en',
lang: 'en',
keys: KEYS_INCLUDING_SOME_WITH_BRACES,
translations: [],
story: mainStory,
});
expect(result).toEqual({
reactIntlId1: 'Hello there!',
reactIntlId3: 'Hello {NAME}!'
});
});
});
4 changes: 3 additions & 1 deletion src/server/collectReactIntlTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import type {
} from '../common/types';

export default function collectReactIntlTranslations({
originalLang,
lang,
keys,
translations,
story,
}: {|
originalLang: string,
lang: string,
keys: MapOf<InternalKeyT>,
translations: Array<InternalTranslationT>,
Expand All @@ -31,7 +33,7 @@ export default function collectReactIntlTranslations({
const key = keys[keyId];
const { reactIntlId } = key;
if (!reactIntlId) return;
if (key.text.indexOf('{') >= 0) {
if (key.text.indexOf('{') >= 0 || lang === originalLang) {
finalTranslations[reactIntlId] = key.text;
}
});
Expand Down
1 change: 1 addition & 0 deletions src/server/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ function compileTranslations({ story: baseStory }: { story?: StoryT } = {}) {
if (_config.fReactIntlOutput) {
const reactIntlLangPath = getReactIntlLangPath(lang);
const reactIntlTranslations = collectReactIntlTranslations({
originalLang: _config.originalLang,
lang,
keys,
translations,
Expand Down