1
0
Fork 0
mirror of https://github.com/voltbonn/profile-picture-generator.git synced 2024-12-22 07:45:04 +00:00
profile.volt.link/src/Localized.js
2021-01-23 19:39:01 +01:00

55 lines
1.3 KiB
JavaScript

import React from 'react'
import {
Localized as LocalizedOriginal,
// withLocalization,
} from '@fluent/react'
import { FluentContext } from '../node_modules/@fluent/react/esm/context.js'
const Localized = props => (
<LocalizedOriginal
key={props.id}
{...props}
elems={{
br: <br />,
...props.elems,
}}
>
<React.Fragment>{props.children}</React.Fragment>
</LocalizedOriginal>
)
// A custom withLocalization to have an empty fallback.
// It is nearly identical to the original.
function withLocalization(Inner) {
function WithLocalization(props) {
const l10n = React.useContext(FluentContext)
const getString = (id, args, fallback) => l10n.getString(id, args, fallback || ' ')
return React.createElement(Inner, { getString, ...props })
}
return WithLocalization
}
export {
withLocalization,
Localized,
Localized as default,
}
/*
import { Localized, withLocalization } from '../Localized/'
<Localized id="translation_id" />
export default withLocalization(componentName)
import Localized from '../Localized/'
<Localized id="translation_id" />
import { withLocalization } from '@fluent/react'
export default withLocalization(componentName)
*/