Skip to content

Commit

Permalink
fix: lingui explicit ids
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Dec 6, 2024
1 parent 5b76e36 commit 9eed0d4
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 17 deletions.
10 changes: 7 additions & 3 deletions apps/mobile/lingui.config.cjs → apps/mobile/lingui.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @type {import('@lingui/conf').LinguiConfig} */
module.exports = {
import { LinguiConfig } from '@lingui/conf';
import { formatter } from '@lingui/format-po';

const config: LinguiConfig = {
locales: ['en', 'pseudo-locale'],
pseudoLocale: 'pseudo-locale',
sourceLocale: 'en',
Expand All @@ -12,5 +14,7 @@ module.exports = {
include: ['src'],
},
],
format: 'po',
format: formatter({ explicitIdAsDefault: true, printLinguiId: true }),
};

export default config;
2 changes: 2 additions & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
"@leather.io/eslint-config": "workspace:*",
"@leather.io/prettier-config": "workspace:*",
"@lingui/cli": "4.11.1",
"@lingui/conf": "5.0.0",
"@lingui/format-po": "5.0.0",
"@lingui/macro": "4.11.1",
"@types/jest": "29.5.12",
"@types/lodash.groupby": "4.6.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function AccountSelectorHeader({ sheetRef }: AccountSelectorHeaderProps)
<Box alignItems="center" justifyContent="center" left={0} position="absolute" right={0}>
<Text variant="heading05">
{t({
id: 'select_account.header_title',
id: 'account_selector.header_title',
message: 'Accounts',
})}
</Text>
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/features/psbt-signer/psbt-signer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function PsbtSigner({ psbtHex, onEdit, onSuccess }: PsbtSignerProps) {
message: 'Show advanced options',
})}
titleOpened={t({
id: 'approver.advanced.show',
id: 'approver.advanced.hide',
message: 'Hide advanced options',
})}
>
Expand Down
32 changes: 24 additions & 8 deletions apps/mobile/src/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isFeatureEnabled } from '@/utils/feature-flag';
import OtaClient from '@crowdin/ota-client';
import { i18n } from '@lingui/core';
import { formatter } from '@lingui/format-po';

const prodHash = 'a14ceb253620ee8933d9539twcj';
const devHash = 'fa04f606d6ca277403b4e49twcj';

const otaClient = new OtaClient(isFeatureEnabled() ? devHash : prodHash);
const prodHash = 'adcc836a66272410c0b94e9twcj'; // with po file format
const devHash = 'a6b025ebb570b783a20df09twcj'; // with po file format
const otaClient = new OtaClient(isFeatureEnabled() ? prodHash : devHash);

export const DEFAULT_LOCALE = 'en';
let LOCALES: string[] = [];
Expand All @@ -18,11 +18,27 @@ export async function initiateI18n() {
i18n.load('en', {});
i18n.activate(DEFAULT_LOCALE);

const content = await otaClient.getStrings();
const translations = await otaClient.getTranslations();

const form = formatter({ explicitIdAsDefault: true, printLinguiId: true });
LOCALES = Object.keys(translations);

Object.keys(translations).map(async locale => {
const contentFile = translations[locale]?.filter(translation =>
translation.file.includes('messages.po')
)[0];
const rawContent = contentFile?.['content'];
// @ts-expect-error: Parser requires 2 options but we ain't giving it that luxury
const parsedContent = await form.parse(rawContent);

const obj: Record<string, string> = {};
// run over every key and set translation as a value for that key
Object.entries(parsedContent).map(translationEntry => {
obj[translationEntry[0]] = translationEntry[1]['translation'];
});

LOCALES = Object.keys(content);
// console.log(obj);

Object.keys(content).map(locale => {
i18n.load(locale, content[locale]);
i18n.load(locale, obj);
});
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@
}
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
}
}
30 changes: 30 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/lib/po.js b/lib/po.js
index 0e2e35d8ffb4d1119a02714c684ae45200ab0a7d..bb9f1a434b2080212d41e65f7e434e0e4560462d 100644
--- a/lib/po.js
+++ b/lib/po.js
@@ -11,7 +11,9 @@ var PO = function () {
};

PO.prototype.save = function (filename, callback) {
+ try {
require('fs').writeFile(filename, this.toString(), callback);
+ } catch(e) {console.log('error on po file load (expected in RN)')}
};

PO.prototype.toString = function () {
@@ -63,6 +65,7 @@ PO.prototype.toString = function () {
};

PO.load = function (filename, callback) {
+ try {
require('fs').readFile(filename, 'utf-8', function (err, data) {
if (err) {
return callback(err);
@@ -70,6 +73,7 @@ PO.load = function (filename, callback) {
var po = PO.parse(data);
callback(null, po);
});
+ } catch(e) {console.log('error on po file load (expected in RN)')}
};

PO.parse = function (data) {
53 changes: 50 additions & 3 deletions pnpm-lock.yaml

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

0 comments on commit 9eed0d4

Please sign in to comment.