Skip to content
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

Support CSP without unsafe-eval #227

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
2 changes: 1 addition & 1 deletion packages/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@messageformat/core": "^3.3.0",
"cross-fetch": "^4.0.0",
"intl-messageformat": "^10.5.14",
"md5": "^2.3.0"
}
}
24 changes: 7 additions & 17 deletions packages/native/src/renderers/MessageFormatRenderer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* eslint-disable class-methods-use-this */
import MessageFormat from '@messageformat/core';

// object to cache MessageFormat classes related to
// specific locales
const MF = {};
import IntlMessageFormat from 'intl-messageformat';

/**
* MessageFormat renderer
Expand All @@ -16,18 +12,12 @@ export default class MessageFormatRenderer {
// construct a MessageFormat class based on locale
// to make dates and other content localizable
const locale = ((localeCode || '').split('_'))[0];
if (!MF[locale]) {
try {
MF[locale] = new MessageFormat(locale, {
strictPluralKeys: false,
});
} catch (err) {
MF[locale] = new MessageFormat('*', {
strictPluralKeys: false,
});
}
let msg;
try {
msg = new IntlMessageFormat(sourceString, locale, undefined, { ignoreTag: true });
} catch (err) {
msg = new IntlMessageFormat(sourceString, undefined, undefined, { ignoreTag: true });
}
const msg = MF[locale].compile(sourceString);
return msg(params);
return msg.format(params);
}
}
Loading