Skip to content

Commit

Permalink
Pull translations from Phrase using locale name (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
adenj authored Oct 14, 2024
1 parent 15c0c16 commit dad4649
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .changeset/swift-crabs-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@vocab/phrase': patch
---

Fix translation issue caused by mismatched Phrase locale identifiers.

Previous behaviour meant that translations were pushed using the locale name in Phrase, but Vocab was retrieving translations by locale code. Phrase locale codes and locale names are not always aligned. This would lead to Vocab searching for translations by code rather than name, often resulting in missing translations.

Vocab now consistently pushes and pulls translations using Phrase’s locale name, regardless of the locale code set in Phrase.
8 changes: 4 additions & 4 deletions packages/phrase/src/phrase-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ export async function pullAllTranslations(
const phraseResult = await callPhrase<
Array<{
key: { name: string };
locale: { code: string };
locale: { name: string };
content: string;
}>
>(`translations?branch=${branch}&per_page=100`);

const translations: TranslationsByLanguage = {};

for (const r of phraseResult) {
if (!translations[r.locale.code]) {
translations[r.locale.code] = {};
if (!translations[r.locale.name]) {
translations[r.locale.name] = {};
}
translations[r.locale.code][r.key.name] = { message: r.content };
translations[r.locale.name][r.key.name] = { message: r.content };
}

return translations;
Expand Down

0 comments on commit dad4649

Please sign in to comment.