Skip to content

Commit

Permalink
Hide ru locale (#186)
Browse files Browse the repository at this point in the history
* Remove locale auto detect

* Hide ru locale

---------

Co-authored-by: Maksim Sitnikov <[email protected]>
  • Loading branch information
imsitnikov and Maksim Sitnikov authored Mar 22, 2024
1 parent 75940c7 commit 5e06b7c
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 55 deletions.
2 changes: 1 addition & 1 deletion next-i18next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
i18n: {
locales: ['en', 'ru'],
locales: ['en' /*, 'ru'*/],
defaultLocale: 'en',
defaultNS: 'common',
ignoreJSONStructure: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {GetStaticPaths, GetStaticPathsResult, GetStaticProps} from 'next';
import React from 'react';
import {Section} from 'src/components/NavigationLayout/types';

import {Component} from '../../../../components/Component/Component';
import {ComponentsLayout} from '../../../../components/ComponentsLayout/ComponentsLayout';
import {Layout} from '../../../../components/Layout/Layout';
import {libs} from '../../../../content/components';
import {useLocaleRedirect} from '../../../../hooks/useLocaleRedirect';
import {getLibComponents} from '../../../../utils';
import {getI18nPaths, getI18nProps} from '../../../../utils/i18next';
import {Component} from '../../../components/Component/Component';
import {ComponentsLayout} from '../../../components/ComponentsLayout/ComponentsLayout';
import {Layout} from '../../../components/Layout/Layout';
import {libs} from '../../../content/components';
import {useLocaleRedirect} from '../../../hooks/useLocaleRedirect';
import {getLibComponents} from '../../../utils';
import {getI18nPaths, getI18nProps} from '../../../utils/i18next';

export const getStaticPaths: GetStaticPaths = async () => {
const paths = getI18nPaths().reduce<GetStaticPathsResult['paths']>((acc, localeItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {useTranslation} from 'next-i18next';
import {useRouter} from 'next/router';
import React from 'react';

import {Layout} from '../../../../components/Layout/Layout';
import {libs} from '../../../../content/components';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../../../utils';
import {Layout} from '../../../components/Layout/Layout';
import {libs} from '../../../content/components';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../../utils';

export const getStaticPaths: GetStaticPaths = async () => {
const paths = getI18nPaths().reduce<GetStaticPathsResult['paths']>((acc, localeItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {useTranslation} from 'next-i18next';
import {useRouter} from 'next/router';
import React from 'react';

import {Layout} from '../../../components/Layout/Layout';
import {libs} from '../../../content/components';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../../utils';
import {Layout} from '../../components/Layout/Layout';
import {libs} from '../../content/components';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../utils';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {GetStaticPaths, GetStaticPathsResult, GetStaticProps} from 'next';
import React from 'react';
import {Section} from 'src/components/NavigationLayout/types';

import {DesignArticle} from '../../../../components/DesignArticle/DesignArticle';
import {DesignLayout} from '../../../../components/DesignLayout/DesignLayout';
import {Layout} from '../../../../components/Layout/Layout';
import {sections as designSections} from '../../../../content/design';
import {useLocaleRedirect} from '../../../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../../../../utils/i18next';
import {DesignArticle} from '../../../components/DesignArticle/DesignArticle';
import {DesignLayout} from '../../../components/DesignLayout/DesignLayout';
import {Layout} from '../../../components/Layout/Layout';
import {sections as designSections} from '../../../content/design';
import {useLocaleRedirect} from '../../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../../../utils/i18next';

export const getStaticPaths: GetStaticPaths = async () => {
const paths = getI18nPaths().reduce<GetStaticPathsResult['paths']>((acc, localeItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {useTranslation} from 'next-i18next';
import {useRouter} from 'next/router';
import React from 'react';

import {Layout} from '../../../../components/Layout/Layout';
import {sections} from '../../../../content/design';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../../../utils';
import {Layout} from '../../../components/Layout/Layout';
import {sections} from '../../../content/design';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../../utils';

export const getStaticPaths: GetStaticPaths = async () => {
const paths = getI18nPaths().reduce<GetStaticPathsResult['paths']>((acc, localeItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {useTranslation} from 'next-i18next';
import {useRouter} from 'next/router';
import React from 'react';

import {Layout} from '../../../components/Layout/Layout';
import {sections} from '../../../content/design';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../../utils';
import {Layout} from '../../components/Layout/Layout';
import {sections} from '../../content/design';
import {getI18nPaths, getI18nProps, getLocaleLink} from '../../utils';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/[locale]/icons.tsx → src/[locale]/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {GetStaticPaths, GetStaticProps} from 'next';
import {useRouter} from 'next/router';
import React from 'react';

import {Icons} from '../../components/Icons';
import {Layout} from '../../components/Layout/Layout';
import {useLocaleRedirect} from '../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../../utils/i18next';
import {Icons} from '../components/Icons';
import {Layout} from '../components/Layout/Layout';
import {useLocaleRedirect} from '../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../utils/i18next';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/[locale]/index.tsx → src/[locale]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {GetStaticPaths, GetStaticProps} from 'next';

import {Landing} from '../../components/Landing/Landing';
import {Layout} from '../../components/Layout/Layout';
import {useLocaleRedirect} from '../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../../utils/i18next';
import {Landing} from '../components/Landing/Landing';
import {Layout} from '../components/Layout/Layout';
import {useLocaleRedirect} from '../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../utils/i18next';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {GetStaticPaths, GetStaticPathsResult, GetStaticProps} from 'next';

import {Layout} from '../../../components/Layout/Layout';
import {Library} from '../../../components/Library/Library';
import {useLocaleRedirect} from '../../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps, getLibById, getLibsList} from '../../../utils';
import {Layout} from '../../components/Layout/Layout';
import {Library} from '../../components/Library/Library';
import {useLocaleRedirect} from '../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps, getLibById, getLibsList} from '../../utils';

const libs = getLibsList();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {GetStaticPaths, GetStaticProps} from 'next';
import {useTranslation} from 'next-i18next';

import {Layout} from '../../../components/Layout/Layout';
import {Libraries} from '../../../components/Libraries/Libraries';
import {useLocaleRedirect} from '../../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../../../utils/i18next';
import {Layout} from '../../components/Layout/Layout';
import {Libraries} from '../../components/Libraries/Libraries';
import {useLocaleRedirect} from '../../hooks/useLocaleRedirect';
import {getI18nPaths, getI18nProps} from '../../utils/i18next';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Menu/LocalePicker/LocalePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const LocalePicker: React.FC = () => {
const {i18n} = useTranslation();
const router = useRouter();

if (i18nextConfig.i18n.locales.length < 2) {
return null;
}

return (
<div className={b()}>
<RadioButton
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useLocaleRedirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export const useLocaleRedirect = () => {

const localStorageLocale = localStorage.getItem(LOCALE_LOCAL_STORAGE_KEY);

const correctLocale = localStorageLocale
? localStorageLocale
: i18nextConfig.i18n.defaultLocale;
const correctLocale =
localStorageLocale && i18nextConfig.i18n.locales.includes(localStorageLocale)
? localStorageLocale
: i18nextConfig.i18n.defaultLocale;

if (currentLocale !== correctLocale) {
const currentPath = router.asPath;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/components/[libId]/[componentId].tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Support for default locale without path prefix
import {GetStaticPaths} from 'next';

import {ComponentPage, getStaticProps} from '../../../[locale]/components/[libId]/[componentId]';
import {libs} from '../../../content/components';
import {ComponentPage, getStaticProps} from '../../[locale]/components/[libId]/[componentId]';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/components/[libId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Support for default locale without path prefix
import {GetStaticPaths} from 'next';

import {LibraryComponentsPage, getStaticProps} from '../../../[locale]/components/[libId]';
import {libs} from '../../../content/components';
import {LibraryComponentsPage, getStaticProps} from '../../[locale]/components/[libId]';

export const getStaticPaths: GetStaticPaths = async () => {
const paths = libs.map((libItem) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Support for default locale without path prefix
export {default, getStaticProps} from '../[locale]/components';
export {default, getStaticProps} from '../../[locale]/components';
2 changes: 1 addition & 1 deletion src/pages/design/[sectionId]/[articleId].tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Support for default locale without path prefix
import {GetStaticPaths} from 'next';

import {ArticlePage, getStaticProps} from '../../../[locale]/design/[sectionId]/[articleId]';
import {sections as designSections} from '../../../content/design';
import {ArticlePage, getStaticProps} from '../../[locale]/design/[sectionId]/[articleId]';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/design/[sectionId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Support for default locale without path prefix
import {GetStaticPaths} from 'next';

import {DesignSectionPage, getStaticProps} from '../../../[locale]/design/[sectionId]';
import {sections} from '../../../content/design';
import {DesignSectionPage, getStaticProps} from '../../[locale]/design/[sectionId]';

export const getStaticPaths: GetStaticPaths = async () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/design/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Support for default locale without path prefix
export {default, getStaticProps} from '../[locale]/design';
export {default, getStaticProps} from '../../[locale]/design';
2 changes: 1 addition & 1 deletion src/pages/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Support for default locale without path prefix
export {default, getStaticProps} from './[locale]/icons';
export {default, getStaticProps} from '../[locale]/icons';
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Support for default locale without path prefix
export {default, getStaticProps} from './[locale]/index';
export {default, getStaticProps} from '../[locale]/index';
2 changes: 1 addition & 1 deletion src/pages/libraries/[libId].tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Support for default locale without path prefix
import {GetStaticPaths} from 'next';

import {LibraryPage, getStaticProps} from '../../[locale]/libraries/[libId]';
import {getLibsList} from '../../utils';
import {LibraryPage, getStaticProps} from '../[locale]/libraries/[libId]';

const libs = getLibsList();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/libraries/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Support for default locale without path prefix
export {default, getStaticProps} from '../[locale]/libraries';
export {default, getStaticProps} from '../../[locale]/libraries';

0 comments on commit 5e06b7c

Please sign in to comment.