-
Notifications
You must be signed in to change notification settings - Fork 17
MWPW-189894: Lingo issue with placeholder fix #748
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
Merged
Merged
Changes from 31 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
edb4791
MWPW-189894: fix: Lingo placeholders in Studio card preview (dictiona…
seanchoi-dev 9ef385d
Revert "MWPW-189894: fix: Lingo placeholders in Studio card preview (…
seanchoi-dev 4c1e9ff
MWPW-189894: Fix - Lingo placeholders in Studio card preview
seanchoi-dev fe6a34d
Merge branch 'main' into MWPW-189894
seanchoi-dev 11c062f
MWPW-189894: fix - align Lingo placeholders with Akamai country and r…
seanchoi-dev 7e76079
Revert "MWPW-189894: Fix - Lingo placeholders in Studio card preview"
seanchoi-dev d489b47
MWPW-189894: Fix - Lingo placeholders in Studio card preview
seanchoi-dev 78f560a
Merge branch 'main' into MWPW-189894
seanchoi-dev 38e9894
MWPW-189894: Applying Nicolas's comment.
seanchoi-dev 2f67cd8
Merge branch 'main' into MWPW-189894
seanchoi-dev 67e81a1
MWPW-189894: nit - format fix
seanchoi-dev ada1bea
Merge branch 'main' into MWPW-189894
seanchoi-dev afaf786
MWPW-189894: Applying Nicolas's comment 2.
seanchoi-dev bebe16c
Merge branch 'main' into MWPW-189894
seanchoi-dev 5f890a1
Revert "MWPW-189894: Fix - Lingo placeholders in Studio card preview"
seanchoi-dev 9b6408f
MWPW-189894: Applying Nicolas's comment 3.
seanchoi-dev 31ea9b5
MWPW-189894: Nit: more named variable.
seanchoi-dev 396dadb
Merge branch 'main' into MWPW-189894
seanchoi-dev f9cd222
MWPW-189894: Removing Akamai/geo merge
seanchoi-dev 82eef2b
MWPW-189894: Reverting the cache.js country-aware key and checking fo…
seanchoi-dev 92445f8
MWPW-189894: unit test update, fetchResult update
seanchoi-dev f0380ee
MWPW-189894: Applied npeltier’s suggestion on getRequestInfos
seanchoi-dev de3a795
MWPW-189894: For npeltier's comment
seanchoi-dev c87863a
MWPW-189894: nit: remove re-export
seanchoi-dev 1cf2108
MWPW-189894: polishing logic including remove double loading and remo…
seanchoi-dev 1132aee
MWPW-189894: nit: update some comments.
seanchoi-dev 70e6927
MWPW-189894: Splitting fetchFragment into two pipeline transformers.
seanchoi-dev 7d45741
MWPW-189894: relocate some of functions.
seanchoi-dev 9ea4692
MWPW-189894: Using body.path instead hard-coded path for the fallback.
seanchoi-dev 0cb7389
MWPW-189894: Unit tests updates.
seanchoi-dev cbeccca
Merge branch 'main' into MWPW-189894
npeltier 5820296
Merge branch 'main' into MWPW-189894
seanchoi-dev 702dcee
MWPW-189894: Rename defaultLanguageVariation -> defaultLanguage
seanchoi-dev b6552a9
MWPW-189894: Handling double computing
seanchoi-dev bf61073
Merge branch 'main' into MWPW-189894
Axelcureno b37a6ab
Merge branch 'main' into MWPW-189894
seanchoi-dev 9edc248
Merge branch 'main' into MWPW-189894
afmicka 2fe294a
Merge branch 'main' into MWPW-189894
seanchoi-dev 5e3f989
MWPW-189894: unit test updates to reach out 100% code coverage
seanchoi-dev 0d78468
Merge branch 'main' into MWPW-189894
afmicka c52ea30
Merge branch 'main' into MWPW-189894
afmicka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
io/www/src/fragment/transformers/defaultLanguageVariation.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import { fetch, getFragmentId } from '../utils/common.js'; | ||
| import { logDebug } from '../utils/log.js'; | ||
| import { odinReferences, odinUrl } from '../utils/paths.js'; | ||
| import { getDefaultLocaleCode, getLocaleCode, getRegionLocales, parseLocaleCode } from '../locales.js'; | ||
|
|
||
| /** | ||
| * Resolves the fragment body for the default language of the requested locale. | ||
| * On success, sets `context.defaultLocale` (when `locale` is omitted, to `parsedLocale`). | ||
| * | ||
| * @param {*} context - Must include `surface`, `fragmentPath`, `body`, `parsedLocale`. `locale` is optional (request param). | ||
| * @returns {Promise<object>} Success and error shapes: | ||
| * - No `locale` param: `{ body, parsedLocale, status: 200 }`. `defaultLocale` is not on the return value; read `context.defaultLocale` (set to `parsedLocale`). | ||
| * - Normal success after resolving default language: `{ body, defaultLocale, status: 200 }` (also `context.defaultLocale`). | ||
| * - Failure: `{ status, message }` from unknown locale, fragment-id lookup, or default-locale fetch errors. | ||
| */ | ||
| export async function getDefaultLanguageVariation(context) { | ||
| let { body } = context; | ||
| const { surface, locale, fragmentPath, preview, parsedLocale } = context; | ||
| if (!locale) { | ||
| context.defaultLocale = parsedLocale; | ||
| return { body, parsedLocale, status: 200 }; | ||
| } | ||
| const defaultLocale = getDefaultLocaleCode(surface, locale); | ||
| if (!defaultLocale) { | ||
| return { status: 400, message: `Default locale not found for requested locale '${locale}'` }; | ||
| } | ||
| if (defaultLocale !== parsedLocale) { | ||
| logDebug(() => `Looking for fragment id for ${surface}/${defaultLocale}/${fragmentPath}`, context); | ||
| const defaultLocaleIdUrl = odinUrl(surface, { locale: defaultLocale, fragmentPath, preview }); | ||
| const { id: defaultLocaleId, status, message } = await getFragmentId(context, defaultLocaleIdUrl, 'default-locale-id'); | ||
| if (status != 200) { | ||
| return { status, message }; | ||
| } | ||
| const defaultLocaleUrl = odinReferences(defaultLocaleId, true, preview); | ||
| const response = await fetch(defaultLocaleUrl, context, 'default-locale-fragment'); | ||
| if (response.status != 200 || !response.body) { | ||
| /* c8 ignore next */ | ||
| const message = response.message || 'Error fetching default locale fragment'; | ||
| /* c8 ignore next */ | ||
| return { status: response.status || 503, message }; | ||
| } | ||
| ({ body } = response); | ||
| } | ||
| context.defaultLocale = defaultLocale; | ||
| return { body, defaultLocale, status: 200 }; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the locale used for regional paths and personalization. | ||
| * If the request uses the default locale code but country differs from that locale's default country and maps to a | ||
| * known region for that language on the surface, returns that regional code (e.g. fr_FR + CA → fr_CA). | ||
| * If the requested locale is already a regional code, it is preserved when no country override applies. | ||
| * @param {*} context | ||
| * @returns {string} | ||
| */ | ||
| export function computeRegionLocale(context) { | ||
| const { locale, defaultLocale: defaultLocaleCode, surface } = context; | ||
| const country = context.country?.toUpperCase(); | ||
| const [, defaultCountry] = parseLocaleCode(defaultLocaleCode); | ||
| const defaultCountryUpper = defaultCountry?.toUpperCase(); | ||
| const effectiveCountry = country && defaultCountryUpper != null && country !== defaultCountryUpper ? country : null; | ||
|
|
||
| let regionLocale = locale; | ||
| if (locale !== defaultLocaleCode || effectiveCountry != null) { | ||
| const regionObjects = getRegionLocales(surface, defaultLocaleCode, true); | ||
| const regionLocaleObject = | ||
| effectiveCountry != null ? regionObjects.find((r) => r.country?.toUpperCase() === effectiveCountry) : null; | ||
| const mapped = regionLocaleObject ? getLocaleCode(regionLocaleObject) : null; | ||
| regionLocale = mapped || locale; | ||
| } | ||
| logDebug( | ||
| () => | ||
| `Computed region locale '${regionLocale}' for requested locale '${locale}' with country '${country}' on surface '${surface}'`, | ||
| context, | ||
| ); | ||
| return regionLocale; | ||
| } | ||
|
|
||
| const TRANSFORMER_NAME = 'defaultLanguageVariation'; | ||
|
|
||
| /** | ||
| * Runs after `fetchFragment` init. Awaits `promises.fetchFragment` (phase 1), then default-language variation + | ||
| * `computeRegionLocale`. Result is `promises.defaultLanguageVariation`. | ||
| */ | ||
| async function init(initContext) { | ||
| const early = await initContext.promises?.fetchFragment; | ||
| if (!early) { | ||
| return { status: 400, message: 'fetchFragment init not available' }; | ||
| } | ||
| if (early.status !== 200) { | ||
| return early; | ||
| } | ||
| const { body: earlyBody, parsedLocale, surface, fragmentPath } = early; | ||
| let context = { ...initContext, body: earlyBody, parsedLocale, surface, fragmentPath }; | ||
| const variationResult = await getDefaultLanguageVariation(context); | ||
| /* c8 ignore next 3 — default-locale fetch errors covered via pipeline / customize tests */ | ||
| if (variationResult.status != 200) { | ||
| return variationResult; | ||
| } | ||
| context = { ...context, body: variationResult.body }; | ||
| const defaultLocale = context.defaultLocale; | ||
| const regionLocale = computeRegionLocale({ ...context, defaultLocale }); | ||
| return { | ||
| ...initContext, | ||
| status: 200, | ||
| body: variationResult.body, | ||
| parsedLocale, | ||
| surface, | ||
| fragmentPath, | ||
| defaultLocale, | ||
| locale: regionLocale, | ||
| regionLocale, | ||
| }; | ||
| } | ||
|
|
||
| async function defaultLanguageVariation(context) { | ||
| const response = await context.promises?.[TRANSFORMER_NAME]; | ||
| if (response?.status !== 200) { | ||
| return response; | ||
| } | ||
| return { | ||
| ...context, | ||
| body: response.body, | ||
| parsedLocale: response.parsedLocale, | ||
| surface: response.surface, | ||
| fragmentPath: response.fragmentPath, | ||
| defaultLocale: response.defaultLocale, | ||
| locale: response.locale, | ||
| regionLocale: response.regionLocale, | ||
| }; | ||
| } | ||
|
|
||
| export const transformer = { | ||
| name: TRANSFORMER_NAME, | ||
| init, | ||
| process: defaultLanguageVariation, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.