mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 18:46:17 +00:00
move useI18n to i18n.ts
Since we are using the react-i18n babel loader plugin, useI18n can only be used once per file. Also we have to remember to add the istanbul ignore next comment each time we use it. By moving this to a common file, it can be easily copied and pasted when a new submodule is created and we don't have to remember the rules when calling it.
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
|
||||
// provides translation for notification text
|
||||
|
||||
import { Replacements, useI18n } from '@shopify/react-i18n';
|
||||
import { Replacements } from '@shopify/react-i18n';
|
||||
import React from 'react';
|
||||
import { I18nId } from './i18n';
|
||||
import { I18nId, useI18n } from './i18n';
|
||||
|
||||
type NotificationActionProps = {
|
||||
messageId: I18nId;
|
||||
@@ -16,8 +16,7 @@ const NotificationAction: React.VoidFunctionComponent<NotificationActionProps> =
|
||||
messageId,
|
||||
replacements,
|
||||
}) => {
|
||||
// istanbul ignore next: babel-loader rewrites this line
|
||||
const [i18n] = useI18n();
|
||||
const i18n = useI18n();
|
||||
|
||||
return <>{i18n.translate(messageId, replacements)}</>;
|
||||
};
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
// provides translation for notification text
|
||||
|
||||
import { Replacements, useI18n } from '@shopify/react-i18n';
|
||||
import { Replacements } from '@shopify/react-i18n';
|
||||
import React from 'react';
|
||||
import { I18nId } from './i18n';
|
||||
import { I18nId, useI18n } from './i18n';
|
||||
|
||||
type NotificationMessageProps = {
|
||||
messageId: I18nId;
|
||||
@@ -16,8 +16,7 @@ const NotificationMessage: React.VoidFunctionComponent<NotificationMessageProps>
|
||||
messageId,
|
||||
replacements,
|
||||
}) => {
|
||||
// istanbul ignore next: babel-loader rewrites this line
|
||||
const [i18n] = useI18n();
|
||||
const i18n = useI18n();
|
||||
|
||||
let message = i18n.translate(messageId, replacements) as
|
||||
| React.ReactElement
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
//
|
||||
// Notification translation keys.
|
||||
|
||||
import { I18n, useI18n as useShopifyI18n } from '@shopify/react-i18n';
|
||||
|
||||
export function useI18n(): I18n {
|
||||
// istanbul ignore next: babel-loader rewrites this line
|
||||
const [i18n] = useShopifyI18n();
|
||||
return i18n;
|
||||
}
|
||||
|
||||
export enum I18nId {
|
||||
AppNoUpdateFound = 'app.noUpdateFound',
|
||||
BleUnexpectedError = 'ble.unexpectedError',
|
||||
|
||||
Reference in New Issue
Block a user