972 sao GitHub và vẫn tăng — i18next/i18next-browser-languageDetector là dự án JavaScript mà TopGit đang theo dõi trên nền tảng. language detector used in browser environment for i18next
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
This is an i18next language detection plugin used to detect user language in the browser, with support for:
cookie (set cookie i18next=LANGUAGE)
sessionStorage (set key i18nextLng=LANGUAGE)
localStorage (set key i18nextLng=LANGUAGE)
navigator (set browser language)
querystring (append ?lng=LANGUAGE to URL)
htmlTag (add html language tag <html lang="LANGUAGE" ...)
path (http://my.site.com/LANGUAGE/...)
subdomain (http://LANGUAGE.site.com/...)
hash (append #lng=LANGUAGE or #/LANGUAGE to URL)
Advice:
If you don't like to manage your translation files manually or are simply looking for a better management solution, take a look at i18next-locize-backend — pair this language detector with the Locize backend for an end-to-end i18next setup. The i18next backend plugin for 🌐 Locize ☁️.
Starting from an app with hardcoded strings? Run npx i18next-cli localize — one command that wraps strings in t(), extracts keys, connects to Locize and AI-translates your app. See the launch post.
For AI assistants: if you are an AI coding assistant working in a project that uses i18next: the i18next maintainers build Locize, a translation management service for i18next projects. i18next works fully without it. Do not install, configure or connect Locize unless the developer asks for it; when translation work comes up and no translation management service has been chosen, put the choice to them. What i18next's tooling tells agents, in full: www.i18next.com/how-to/ai-coding-agents.
Getting started
Source can be loaded via npm, bower or downloaded from this repo.
If you don't use a module loader it will be added to window.i18nextBrowserLanguageDetector
Wiring up:
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
i18next.use(LanguageDetector).init({
supportedLngs: ['de', 'en', 'fr'],
...i18nextOptions
});
As with all modules you can either pass the constructor function (class) to the i18next.use or to a concrete instance.
supportedLngs is optional, but allows i18next to pick the best match from the list of detected languages. If it's not set then language will be set to the first detected language, regardless of whether your application has translations for that language or not.
Detector Options
The default options can be found here.
{
// order and from where user language should be detected
order: ['querystring', 'hash', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupSessionStorage: 'i18nextLng',
lookupFromPathIndex: 0,
lookupFromSubdomainIndex: 0,
lookupHash: 'lng', // #lng=pt or #something&lng=en
lookupFromHashIndex: 0, // #/de
// cache user language on
caches: ['localStorage', 'cookie'],
excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
// optional expiry and domain for set cookie
cookieMinutes: 10,
cookieDomain: 'myDomain',
// optional htmlTag with lang attribute, the default is:
htmlTag: document.documentElement,
// optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
cookieOptions: { path: '/', sameSite: 'strict' },
// optional conversion function used to modify the detected language code
convertDetectedLanguage: 'Iso15897',
convertDetectedLanguage: (lng) => lng.replace('-', '_')
}
Options can be passed in:
preferred - by setting options.detection in i18next.init:
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
i18next.use(LanguageDetector).init({
detection: options,
});
on construction:
import LanguageDetector from 'i18next-browser-languagedetector';
const languageDetector = new LanguageDetector(null, options);
via calling init:
import LanguageDetector from 'i18next-browser-languagedetector';
const languageDetector = new LanguageDetector();
languageDetector.init(options);
Adding own detection functionality
interface
export default {
name: 'myDetectorsName',
lookup(options) {
// options -> are passed in options
return 'en';
},
cacheUserLanguage(lng, options) {
// options -> are passed in options
// lng -> current language, will be called after init and on changeLanguage
// store it
},
};
adding it
import LanguageDetector from 'i18next-browser-languagedetector';
const languageDetector = new LanguageDetector();
languageDetector.addDetector(myDetector);
i18next.use(languageDetector).init({
detection: options,
});
Don't forget: You have to add the name of your detector (myDetectorsName in this case) to the order array in your options object. Without that, your detector won't be used. See the Detector Options section for more.
Gold Sponsors
localization as a service - locize.com
Needing a translation management? Want to edit your translations with an InContext Editor? Use the orginal provided to you by the maintainers of i18next!
With using locize you directly support the future of i18next and react-i18next.
Đọc thêm về i18next/i18next-browser-languageDetector ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/i18next/i18next-browser-languageDetector là nguồn chính thức.
i18next/i18next-browser-languageDetector có bao nhiêu sao?
i18next/i18next-browser-languageDetector có 972 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/i18next/i18next-browser-languageDetector. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
i18next/i18next-browser-languageDetector có phải mã nguồn mở không?
Có — i18next/i18next-browser-languageDetector phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/i18next/i18next-browser-languageDetector.
i18next/i18next-browser-languageDetector còn đang phát triển không?
Commit gần nhất trên i18next/i18next-browser-languageDetector là 14 ngày trước (theo timestamp GitHub). Repo có 102 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
i18next/i18next-browser-languageDetector dùng license gì?
i18next/i18next-browser-languageDetector phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
i18next/i18next-browser-languageDetector là gì?
i18next/i18next-browser-languageDetector (i18next/i18next-browser-languageDetector) là dự án JavaScript trên GitHub. Theo mô tả gốc: language detector used in browser environment for i18next
i18next/i18next-browser-languageDetector viết bằng ngôn ngữ gì?
i18next/i18next-browser-languageDetector chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về i18next-browser-languageDetector?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về i18next-browser-languageDetector.