Skip to content

Commit

Permalink
Merge branch 'release/1.3' of https://github.com/qubic/explorer-frontend
Browse files Browse the repository at this point in the history
 into release/1.4
  • Loading branch information
AndyQus committed May 6, 2024
2 parents 8cf2e65 + bf21ea3 commit 92a61da
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/app/main/404/Error404Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import nl from './i18n/nl';
import ru from './i18n/ru';
import pt from './i18n/pt';
import tr from './i18n/tr';
import cn from './i18n/cn';
import jp from './i18n/jp';
import zh from './i18n/zh';
import ja from './i18n/ja';
import ar from './i18n/ar';
import Error404Page from './Error404Page';

Expand All @@ -20,8 +20,8 @@ i18next.addResourceBundle('nl', 'error404Page', nl);
i18next.addResourceBundle('ru', 'error404Page', ru);
i18next.addResourceBundle('pt', 'error404Page', pt);
i18next.addResourceBundle('tr', 'error404Page', tr);
i18next.addResourceBundle('cn', 'error404Page', cn);
i18next.addResourceBundle('jp', 'error404Page', jp);
i18next.addResourceBundle('zh', 'error404Page', zh);
i18next.addResourceBundle('ja', 'error404Page', ja);
i18next.addResourceBundle('ar', 'error404Page', ar);

const Error404Config = {
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/app/main/apps/network/NetworkConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import nl from './i18n/nl';
import ru from './i18n/ru';
import pt from './i18n/pt';
import tr from './i18n/tr';
import cn from './i18n/cn';
import jp from './i18n/jp';
import zh from './i18n/zh';
import ja from './i18n/ja';
import ar from './i18n/ar';
import NetworkPage from './NetworkPage';
import TickPage from './tick/TickPage';
Expand All @@ -24,8 +24,8 @@ i18next.addResourceBundle('nl', 'networkPage', nl);
i18next.addResourceBundle('ru', 'networkPage', ru);
i18next.addResourceBundle('pt', 'networkPage', pt);
i18next.addResourceBundle('tr', 'networkPage', tr);
i18next.addResourceBundle('cn', 'networkPage', cn);
i18next.addResourceBundle('jp', 'networkPage', jp);
i18next.addResourceBundle('zh', 'networkPage', zh);
i18next.addResourceBundle('ja', 'networkPage', ja);
i18next.addResourceBundle('ar', 'networkPage', ar);

const NetworkConfig = {
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 2 additions & 13 deletions src/app/store/i18nSlice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSelector, createSlice } from '@reduxjs/toolkit';
import i18n from 'src/i18n';
import { setDefaultSettings } from './fuse/settingsSlice';
import suggestedLanguages from '../utils/constants';

export const changeLanguage = (languageId) => (dispatch, getState) => {
const { direction } = getState().fuse.settings.defaults;
Expand All @@ -20,19 +21,7 @@ const i18nSlice = createSlice({
name: 'i18n',
initialState: {
language: i18n.options.lng, // Use the saved language from localStorage if available
languages: [
{ id: 'en', title: 'English' },
{ id: 'de', title: 'Deutsch' },
{ id: 'es', title: 'Español' },
{ id: 'fr', title: 'Français' },
{ id: 'nl', title: 'Nederlands' },
{ id: 'ru', title: 'Русский' },
{ id: 'pt', title: 'Português' },
{ id: 'tr', title: 'Türkçe' },
{ id: 'cn', title: '中文' },
{ id: 'jp', title: '日本語' },
{ id: 'ar', title: 'العربية' },
],
languages: suggestedLanguages,
},
reducers: {
languageChanged: (state, action) => {
Expand Down
15 changes: 15 additions & 0 deletions src/app/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const suggestedLanguages = [
{ id: 'en', title: 'English' },
{ id: 'de', title: 'Deutsch' },
{ id: 'es', title: 'Español' },
{ id: 'fr', title: 'Français' },
{ id: 'nl', title: 'Nederlands' },
{ id: 'ru', title: 'Русский' },
{ id: 'pt', title: 'Português' },
{ id: 'tr', title: 'Türkçe' },
{ id: 'zh', title: '中文' },
{ id: 'ja', title: '日本語' },
{ id: 'ar', title: 'العربية' },
];

export default suggestedLanguages;
39 changes: 21 additions & 18 deletions src/i18n.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import suggestedLanguages from './app/utils/constants';

// the translations
// (tip move them in a JSON file and import them)
Expand All @@ -11,29 +12,31 @@ const resources = {
},
};

// const getInitialLanguage = () => {
// // Check for a stored language in localStorage
// const storedLang = localStorage.getItem('lng');
// if (storedLang) {
// return storedLang;
// }

// // Get browser language
// const browserLang = navigator.language.split('-')[0]; // Extract base language, e.g., 'en' from 'en-US'
// if (browserLang) {
// return browserLang;
// }

// // Default to English if the browser language is not supported
// return 'en';
// };
const getInitialLanguage = () => {
// Check for a stored language in localStorage
const storedLang = localStorage.getItem('lng');
if (storedLang) {
return storedLang;
}

// Get browser language
const browserLang = navigator.language.split('-')[0]; // Extract base language, e.g., 'en' from 'en-US'

if (browserLang) {
const foundLang = suggestedLanguages.find((lng) => browserLang === lng.id);
if (foundLang) {
return browserLang;
}
}
// Default to English if the browser language is not supported
return 'en';
};

i18n
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources,
lng: localStorage.getItem('lng') || 'en',
// lng: getInitialLanguage(),
lng: getInitialLanguage(),

keySeparator: false, // we do not use keys in form messages.welcome

Expand Down

0 comments on commit 92a61da

Please sign in to comment.