react-intl

Unable to use JSON from S3 buck in i18next

早过忘川 提交于 2021-01-29 12:32:54
问题 This is how my i18n file looks like - import i18n from 'i18next' import { initReactI18next } from 'react-i18next' import HttpApi from 'i18next-http-backend'; i18n .use(HttpApi) .use(initReactI18next) .init({ // resources: resourcesObj, initImmediate: false, backend: { loadPath: 'https://bucketlink.amazonaws.com/locales/{{lng}}/{{ns}}.json', crossDomain: true, allowMultiLoading: true, }, lng: "en", fallbackLng: "en", debug: false, ns: ["translations"], defaultNS: "translations", keySeparator:

How to use Intl.NumberFormat with react native?

本小妞迷上赌 提交于 2021-01-02 08:16:11
问题 Im trying to convert a number to price format in react native. How to use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat (Intl.NumberFormat) this with react native? 回答1: Looks like you need the international version of JSC: Android: https://github.com/react-native-community/jsc-android-buildscripts#international-variant For iOS you'd need to use Intl.js polyfill https://github.com/andyearnshaw/Intl.js/ 来源: https://stackoverflow.com/questions

React-Intl how to switch locale and messages from variable

感情迁移 提交于 2020-07-04 11:54:47
问题 I'm trying to figure out how to change language using React-Intl. This is my first React App and it has been made with create-react-app, I'm not using Redux nor Flux. In my index.js I have the following code: import React from 'react'; import ReactDOM from 'react-dom'; import TodoApp from './components/TodoApp'; import registerServiceWorker from './registerServiceWorker'; import './index.css'; // Bootstrap CSS libraries import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap/dist/css

React-Intl how to switch locale and messages from variable

可紊 提交于 2020-07-04 11:53:59
问题 I'm trying to figure out how to change language using React-Intl. This is my first React App and it has been made with create-react-app, I'm not using Redux nor Flux. In my index.js I have the following code: import React from 'react'; import ReactDOM from 'react-dom'; import TodoApp from './components/TodoApp'; import registerServiceWorker from './registerServiceWorker'; import './index.css'; // Bootstrap CSS libraries import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap/dist/css

Why doesn't Intl.NumberFormat work with units in Safari and Firefox?

笑着哭i 提交于 2020-06-16 05:47:08
问题 I'm trying to use the example given here concerning formatting a number. console.log((16).toLocaleString('en-GB', { style: "unit", unit: "liter", unitDisplay: "long" })); I tried it in chrome and it works great. However, in Safari as well as Firefox I get the following errors respectively Error: style must be either "decimal", "percent", or "currency" and Error: invalid value "unit" for option style . From the docs I figured it should work on all browsers after looking at the browser

Translations for constants files in react

和自甴很熟 提交于 2020-05-27 07:18:28
问题 I am trying to find best concept of translations for my react app. I have a higher order component for translations and use it by: export default translate('MyComponent')(MyComponent); And inside a component I have all texts available by props - it works fine for me. But, I have a lot of pure javascript files with constants and also need a tranlations there. There is for example validation schema's with error messages or constats with select elements like: export default [ { value: 'aaa',

using react-intl to translate a message key outside a component

核能气质少年 提交于 2020-03-02 17:14:18
问题 I'm using the react-intl library for internationalization. Inside a component, I use the injectIntl HOC to translate message keys: import {injectIntl} from 'react-intl'; const Component = props => ( const message = props.intl.formatMessage({id: 'message.key'}); // remainder of component omitted ); export default injectIntl(Component); Is it possible to get a message translation if I'm not inside a component? 回答1: Yes it is! You have to setup you application to provide the intl object so that

react-intl - accessing nested messages

眉间皱痕 提交于 2020-02-01 02:48:25
问题 I'm trying to use react-intl package inside an app. The app is rendered on the server so I wrote some code to determine which language to use and serve into IntlProvider . Translations were provided in messages.js file and they look like this: export default { en: { message: '...some message', nested: { anotherMessage: '...another message', } } de: { // ... } } What I do is something like this: // import messages from './messages.js' // Check the locale for the user (based on cookies or other

react-intl - accessing nested messages

自古美人都是妖i 提交于 2020-02-01 02:48:06
问题 I'm trying to use react-intl package inside an app. The app is rendered on the server so I wrote some code to determine which language to use and serve into IntlProvider . Translations were provided in messages.js file and they look like this: export default { en: { message: '...some message', nested: { anotherMessage: '...another message', } } de: { // ... } } What I do is something like this: // import messages from './messages.js' // Check the locale for the user (based on cookies or other

React-intl define messages outside of react

一笑奈何 提交于 2020-01-14 07:41:43
问题 I have utils.js file. export function categoryIdToCategoryName(categoryId) { let name; switch (categoryId) { case constants.RISK_CATEGORY_LOW: name = 'low'; break; case constants.RISK_CATEGORY_MEDIUM: name = 'medium'; break; case constants.RISK_CATEGORY_HIGH: name = 'high'; break; case constants.RISK_CATEGORY_CRITICAL: name = 'critical'; break; default: console.warn('see: /utils/risk.js', 'categoryIdToCategoryName:', categoryId); name = 'unknown'; } return name; } I would like to translate