browser-lang | Detect user 's most preferred language | Web Framework library
kandi X-RAY | browser-lang Summary
kandi X-RAY | browser-lang Summary
Detect user's most preferred language within the given language list.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of browser-lang
browser-lang Key Features
browser-lang Examples and Code Snippets
Community Discussions
Trending Discussions on browser-lang
QUESTION
I have a react app that I have translated into several languages, and also contains some date formatting functionality. I would like to for example, allow the user to change between 12h and 24h time, however when switching to German, automatically change that option to 24h (as Germany typically doesn't use 12h time).
I still want this option to be able to be changed by the user, and I also don't want it to be reset to 24h every time the page reloads.
I'm using i18next
and i18next-browser-languageDetector
to detect the browser language, and currently I have an event bound to i18next
for when the language is manually changed by the user, in order to set these default settings per language, and this works perfectly:
ANSWER
Answered 2021-May-31 at 13:17I managed to solve this issue by first checking if a language had been saved in localstorage, adding this to the i18next options object, then I could check this later to set the defaults.
QUESTION
ANSWER
Answered 2021-May-27 at 07:23You should be rendering the component object you store in state in Apply
, not just using it as a variable.
QUESTION
After converting a react app to single spa which had il8n implemented I am facing a problem where translation.json cannot be accessed hence not fetching the labels.
Should I modify something in the webpack.config.js to get it right
...ANSWER
Answered 2021-May-24 at 14:03The issue is that previously, the React app also served as the server that provided the index.html file along with other static assets (eg. your localized translation json files). In single-spa, that is no longer the case; that is instead now the root-config. You'll need to update your i18next-http-backend loadPath
configuration so that the library tries to retrieve them from the right path which is no longer the root url. Without being familiar with what you want to achieve, you have two options:
- use
__webpack_public_path__
to dynamically create the correct URL to point to the assets served by this microfrontend, eg.loadPath: `${__webpack_public_path__} /locales/{{lng}}/{{ns}}.json`,
- if you have a separate i18n service, point the URL to that. This may also require
crossDomain
andwithCredentials
depending on how that is also configured.
QUESTION
I am setting up the react-i18n-next hook to translate my app and i followed the example that the react-i18n-next use but it throws error like below:
...ANSWER
Answered 2021-May-06 at 05:59There are certain things you need to do in the above code
- First of all you need to make two translation files, in which you are missing some keys and their values.
let suppose translationEN.json -
QUESTION
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
const locales = ['en-GB', 'pl-PL'];
export const supportedLanguages = locales;
const localeResources = {
'en-GB': {
common: require('./locales/en-GB/common.json'),
},
'pl-PL': {
common: require('./locales/pl-PL/common.json'),
},
};
const frozenLocales = Object.freeze(locales);
export function localesImmutable() {
return frozenLocales;
}
const fallbackLanguages = {
pl: ['pl-PL'],
default: ['en-GB'],
};
i18next.services.pluralResolver.addRule('pl', {
numbers: [1, 2, 3],
plurals: function (n) {
return Number(
n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2
);
},
});
const i18n = i18next;
i18n.use(LanguageDetector).init({
resources: localeResources,
fallbackLng: fallbackLanguages,
ns: 'common',
defaultNS: 'common',
react: { wait: true },
debug: false,
cache: { enabled: true },
});
export default i18n;
...ANSWER
Answered 2021-Apr-20 at 10:54You should call addRule
only after the init
is done.
QUESTION
I want to create an multi language app via i18next
package
But the package does not work correctly
here is i18next
file
ANSWER
Answered 2021-Apr-06 at 00:02I think your json missing the translation key work like this:
QUESTION
The translations do not work I only see the keys. Instead of having "Welcome to MySite" I only have "welcome.title MySite".
my i18nextConf.js file
...ANSWER
Answered 2021-Feb-17 at 11:24Those translation files will be served from the base path from where your index.html
is also loaded and in-case it's an app created using create-react-app
, that folder is public.
So I think when you are saying in loadPath
that load files from ./translations/{{lng}}/common.json
, the request actually gets resolved to public/translation/en/common.json
but your files are located at src.....
as you stated.
You can try either moving those files inside public (check this example for reference also ) or you can try the other syntax where you explicitly import the json from each file (inside src) and add it to a resources
object which you pass to configuration as shown here
QUESTION
This is a very strange issue but I was using react-table 7.0.0.rc16 and I recently upgraded to react-table 7.0.1 the problem is my data works in dev mode but as soon I create a react build it wont render anything I would like to know why and I am attaching my package.json for the same. sandbox
Package.json
...ANSWER
Answered 2021-Feb-04 at 07:33This is a problem with react-table v7.0.1, upgrading to v7.0.2 fixes the problem.
It's a minification bug. Here is the exact commit that fixed the problem.
From the Changelog :
7.0.2
- Fixed an issue where the internal flexRenderer would not work correctly in production due to the strangest friggin' minification bug I've ever encountered. 🤷♂️
QUESTION
I've been trying to start a new react project to practice some skills.
And recently I tried to add internationalization and localization, by adding react-i18next
and i18next
.
Simply followed the step by step guide available on https://react.i18next.com and added my translation files.
But when I run the project I get the console error GET https://localhost:8080/locales/en/generic.json 404 (Not Found)
At first I thought that the project was missing a json-loader
so I added to the webpack.config.js
, but the result is the same. I check the paths and all seems right.
Thanks in advance
i18n file
...ANSWER
Answered 2021-Jan-06 at 10:26So I think that o discovered a solution
All I did was add the copy-webpack-plugin
and put the following code to my webpack file
QUESTION
I deployed my nextjs app to Vercel and it was a success.
I can see a preview of the website and even the log saying it works well.
But i try to access the website via the default Vercel domain :
I get an ERR_TOO_MANY_REDIRECTS.
I do not have this problem locally.
I tried :
- Disabling a language redirect that I use (/en for english folks, and / for french people).
- Disabling the language detector of i18next.
But none of these solutions changed anything. Any ideas ?
i18n.js file
...ANSWER
Answered 2021-Jan-02 at 11:25What happend at your server is following:
You enter https://tly-nextjs.vercel.app/ and it is redirected to /en with HTTP-Status-Code 307 (Temporary Redirect).
And /en redirect with 301 (Permanent Redirect) to /.
You can reproduce this by open the Browser-Dev-Tools and have a look at the Network
Tab.
It might be, that you have some kind of url-rewriting activated at your server, which redirect everything to your domain-root.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install browser-lang
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page