Skip to content

Commit

Permalink
Merge pull request codeforboston#1020 from turnerhayes/rename-snippets-2
Browse files Browse the repository at this point in the history
Replace more snippet references. Fixes codeforboston#1019
  • Loading branch information
turnerhayes committed Nov 25, 2018
2 parents a359dc6 + eee5343 commit 06a0d10
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/dev/DevHud.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DevMenu = function ({ devProps, funcs, data, state }) {
</Button>
</Menu.Item>

<Menu.Item header> Snippets</Menu.Item>
<Menu.Item header>Translations</Menu.Item>
<Menu.Item>
<Checkbox
label = { `Mark English translations` }
Expand Down
2 changes: 1 addition & 1 deletion src/localization/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ZH from './zh';
* @summary Exports a function which returns a deep clone of the language translation objects.
*
* @description
* interpolateSnippets() mutates it's localization object, whereas Localization Report in DevHud
* interpolateTranslations() mutates its localization object, whereas Localization Report in DevHud
* compares the raw objects contained in localization files. By providing a function which returns
* cloned data instead of a reference to the imported objects, the two can coexist.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/localization/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export default {
// Benefit Programs Graph, showing benefit programs as lines not areas:
benefitProgramsTitle_v3: `Individual Benefit Amounts as Pay Changes`, // maybe rename as benefitProgramsSubTitle_v1 ? see also BenefitsLineGraph.js
benefitValue_v1: `Benefit Value ($)`, // see BenefitsLineGraph.js
// Snippets that are used in more than one chart, table, or graph:
// Translations that are used in more than one chart, table, or graph:
totalMoney_v1: `Total Money Coming In ($)`, // see StackedAreaGraph.js, StackedBarGraph.js
weeklyPay_v2: `Weekly Pay ($)`,
monthlyPay_v2: `Monthly Pay ($)`,
Expand Down
12 changes: 6 additions & 6 deletions src/utils/getTextForLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// TRANSFORMER FUNCTIONS
import { mergeWith } from 'lodash';
import { interpolateSnippets } from './interpolation.js';
import { interpolateTranslations } from './interpolation.js';

// DATA
import { getLocalizationData } from '../localization/all';
Expand All @@ -12,7 +12,7 @@ import inlineComponents from '../localization/inlineComponents';
const localizations = getLocalizationData();

// store interpolated and (if necessary) merged translations objects
let finishedSnippets = { en: interpolateSnippets(localizations.en, inlineComponents) };
let finishedTranslations = { en: interpolateTranslations(localizations.en, inlineComponents) };

/** Customizes Lodash's mergeWith function to replace arrays completely
* (to avoid arrays of English strings being mixed with arrays of translated
Expand All @@ -35,16 +35,16 @@ const getTextForLanguage = function (langCode) {
langCode = 'en';
}

if (!finishedSnippets[ langCode ]) {
if (!finishedTranslations[ langCode ]) {
// interpolate translations and merge with English (filling in any gaps)
const interpolatedSnippets = interpolateSnippets(localizations[ langCode ], inlineComponents);
const interpolatedTranslations = interpolateTranslations(localizations[ langCode ], inlineComponents);

// deeply merge the object containing translations in langName with English,
// so that we fall back to English if a particular field is missing.
finishedSnippets[ langCode ] = mergeWith({}, finishedSnippets.en, interpolatedSnippets, mergeCustomizer);
finishedTranslations[ langCode ] = mergeWith({}, finishedTranslations.en, interpolatedTranslations, mergeCustomizer);
}

return finishedSnippets[ langCode ];
return finishedTranslations[ langCode ];
}; // End getTextForLanguage()


Expand Down
6 changes: 3 additions & 3 deletions src/utils/interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const interpolateText = function (template, components, langCode) {
};

/** Recursively interpolate each template in a translations object */
const interpolateSnippets = function (translations, components) {
const interpolateTranslations = function (translations, components) {
let named = {},
versionRegex = /_v\d+$/;

Expand Down Expand Up @@ -70,7 +70,7 @@ const interpolateSnippets = function (translations, components) {
} else {
// else: value is a nested object
value.langCode = langCode;
named[ key ] = interpolateSnippets(value, components);
named[ key ] = interpolateTranslations(value, components);
}

} // end for every key in translations
Expand All @@ -79,4 +79,4 @@ const interpolateSnippets = function (translations, components) {
};


export { interpolateText, interpolateSnippets };
export { interpolateText, interpolateTranslations };

0 comments on commit 06a0d10

Please sign in to comment.