我需要根据用户位置和/或浏览器语言设置更改应用程序的语言。 我将如何在i18next中做到这一点? 它必须是i18Next,因为该项目已经设置为可以使用它,并且使用另一个库将使我花很多时间来重构才能正常工作。
到目前为止,这是我的代码。我知道我需要在后端部分做一些事情,只是不知道要做什么。
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import Backend from "i18next-xhr-backend";
i18n
.init({
backend: {
loadPath: "/locales/{{lng}}/{{ns}}.json"
},
fallbackLng: "en",
debug: false,
keySeparator: false,
});
export default i18n;
答案 0 :(得分:0)
我使用了i18next-browser-languagedetector。文档和示例在此处https://github.com/i18next/i18next-browser-languageDetector。琴弦
DECLARE @Table TABLE (PointDescription NVARCHAR(100));
INSERT INTO @Table SELECT 'Meter # Pressure'
INSERT INTO @Table SELECT 'Meter # Gravity'
INSERT INTO @Table SELECT 'Meter # Temperature'
DECLARE @ControlRoomAlarmDataItemXml XML = '<ControlRoomAlarmDataItem><Register /><Description /><Units /><HasAlarms /><LowLowLimitOFF /><LowLowLimitON /><HiLimit /><HiHiLimit /><PointType /><TriggersAlarmWhenOn /><IsDigitallyVerifiedLimit /><AlarmPriority /><HasLeakDetection /><MaximunAllowableOperatingPressure /><IsControlRoomManaged /><IsOnDisplay /></ControlRoomAlarmDataItem>';;
-----------------
-- ANALOG RECORDS
DECLARE @PointDescription NVARCHAR(100);
DECLARE Analog_cursor CURSOR FOR SELECT PointDescription FROM @Table
OPEN Analog_cursor;
FETCH NEXT FROM Analog_cursor INTO @PointDescription;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @ControlRoomAlarmDataItemXml.modify('insert text{sql:variable("@PointDescription")} as first into (/ControlRoomAlarmDataItem/Description/value)[1]')
--SET @ControlRoomAlarmDataItemXml.modify('insert text{sql:variable("@PointDescription")} as first into (/ControlRoomAlarmDataItem/Description[1]/value)[1]')
--SET @ControlRoomAlarmDataItemXml.modify('insert text{sql:variable("@PointDescription")} as first into (/ControlRoomAlarmDataItem/Description/value[1])[1]')
--SET @ControlRoomAlarmDataItemXml.modify('insert text{sql:variable("@PointDescription")} as first into (/ControlRoomAlarmDataItem/Description/value)[1]')
--SET @ControlRoomAlarmDataItemXml.modify('insert sql:variable("@PointDescription") as first into (/ControlRoomAlarmDataItem/Description/value)[1]')
-- This works only if I give the node a default-value...but I DO NOT want that
--SET @ControlRoomAlarmDataItemXml.modify('replace value of (/ControlRoomAlarmDataItem/Description/text())[1] with sql:variable("@PointDescription")')
SELECT @ControlRoomAlarmDataItemXml
FETCH NEXT FROM Analog_cursor INTO @PointDescription;
END;
CLOSE Analog_cursor;
DEALLOCATE Analog_cursor;
并在初始化
const options = {
order: ['querystring', 'navigator'],
lookupQuerystring: 'lng'
}
将添加到您的i18n.js文件中。