Skip to content

Commit

Permalink
Added Chinese translation
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Sep 16, 2024
1 parent fdcd400 commit cf05821
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 11 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ It can be based on an open issue, but also on a spontaneous submission. If the i
- update the file `src/helpers/config/i18n.ts` in the following configuration:
- `locales` needs to include the new BCP 47 format language code.
- `locales_regional_codes` needs to include a new key-value pair to associate the language code with its corresponding regional code.
- update the files `locales/**/common.json` at the fieldset `language`.
- create a new PR and wait for feedback.
12 changes: 12 additions & 0 deletions locales/zh/bookshops.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"results": {
"notfound": "未找到结果。请尝试使用不同的搜索过滤条件。",
"wrongpagination": "没有可用的结果。看起来分页可能已在URL中被修改。请再次尝试搜索。"
},
"form": {
"address": "地址",
"website": "网站",
"description": "描述",
"image": "图片"
}
}
77 changes: 77 additions & 0 deletions locales/zh/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"title": "未知艺术",
"description": "未知艺术是一个俱乐部,它将带您探索全球各地的艺术和独立书店。",
"menu" : {
"home": "首页",
"bookshops": "书店",
"bookshop": "书店"
},
"language" : {
"it": "意大利语",
"en": "英语"
},
"logo": {
"title": "未知艺术标志",
"label": "主标志"
},
"loading": "加载中",
"pagination": {
"current_page": "当前页面",
"page": "页面"
},
"search": {
"title": "搜索书店",
"description": "筛选书店列表",
"field": {
"total": {
"label": "总计"
},
"name": {
"label": "名称"
},
"country": {
"label": "国家"
},
"city": {
"label": "城市"
},
"website": {
"label": "网站",
"option": {
"all": "全部",
"with": "有网站",
"without": "无网站"
}
}
},
"action": {
"dialog": {
"title": "搜索",
"label": "打开书店搜索对话框"
},
"close": {
"label": "关闭书店搜索对话框"
},
"submit": {
"title": "搜索",
"label": "提交书店搜索"
},
"reset": {
"title": "重置",
"label": "重置书店搜索"
}
}
},
"error": {
"description": "{{page}} 页面有问题,您可以稍后访问我们,或尝试重新加载页面。",
"action": {
"reload": {
"title": "重新加载",
"label": "重新加载{{page}}页面"
}
}
},
"notfound": {
"description": "未找到页面,请访问首页以解决问题。"
}
}
8 changes: 8 additions & 0 deletions locales/zh/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"intro": "欢迎,亲爱的读者!",
"content": "未知艺术是您可以在美丽的世界各地与个人、爱好者、思想家、头脑或艺术家建立联系的地方。",
"logo": {
"title": "未知艺术主图",
"label": "主图"
}
}
4 changes: 2 additions & 2 deletions src/app/[locale]/bookshops/[bookshopId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { notFound } from 'next/navigation'

import styles from './bookshop.module.css'

import { locales_codes } from 'helpers/config/i18n'
import { locales_regional_codes } from 'helpers/config/i18n'
import { meta, META_SITE_BASE_URL } from 'helpers/config/meta'
import { getTranslationServer } from 'helpers/utils/getTranslationServer'
import { isImageSecure } from 'helpers/utils/isImageSecure'
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function generateMetadata(
description: t('description'),
url: `${META_SITE_BASE_URL}${locale}/bookshops/${bookshop.id}`,
siteName: meta.siteName,
locale: locales_codes[locale as I18nLocale],
locale: locales_regional_codes[locale as I18nLocale],
type: 'website',
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/bookshops/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Metadata } from 'next'
import { ReactNode } from 'react'

import { locales_codes } from 'helpers/config/i18n'
import { locales_regional_codes } from 'helpers/config/i18n'
import { meta, META_SITE_BASE_URL } from 'helpers/config/meta'
import { getTranslationServer } from 'helpers/utils/getTranslationServer'
import type { ComponentParams } from 'types/component'
Expand All @@ -25,7 +25,7 @@ export async function generateMetadata(
description: t('description'),
url: `${META_SITE_BASE_URL}${locale}/bookshops`,
siteName: meta.siteName,
locale: locales_codes[locale as I18nLocale],
locale: locales_regional_codes[locale as I18nLocale],
type: 'website',
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/[locale]/home.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ test.describe('src / app / [locale] > home', () => {

expect(homePage.locales.getLanguage('en')).toBeDefined()
expect(homePage.locales.getLanguage('it')).toBeDefined()
expect(homePage.locales.getLanguage('zh')).toBeDefined()
})
})
8 changes: 4 additions & 4 deletions src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { dir } from 'i18next'
import type { Metadata, Viewport } from 'next'
import type { ReactNode } from 'react'

import { Analytics } from 'src/components/analytics'
import { Header } from 'src/components/header'
import { font } from 'helpers/config/font'
import { locales, locales_codes } from 'helpers/config/i18n'
import { locales, locales_regional_codes } from 'helpers/config/i18n'
import { meta, META_SITE_BASE_URL } from 'helpers/config/meta'
import { DialogProvider } from 'helpers/providers/dialog'
import { getTranslationServer } from 'helpers/utils/getTranslationServer'
import { isEnvironmentProduction } from 'helpers/utils/isEnvironment'
import { Analytics } from 'src/components/analytics'
import { Header } from 'src/components/header'
import type { ComponentParams } from 'types/component'
import type { I18nLocale } from 'types/i18n'

Expand All @@ -33,7 +33,7 @@ export async function generateMetadata({ params: { locale } }: HomeLayoutProps):
description: t('description'),
url: META_SITE_BASE_URL,
siteName: meta.siteName,
locale: locales_codes[locale as I18nLocale],
locale: locales_regional_codes[locale as I18nLocale],
type: 'website',
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/menu/menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ describe('Components > Menu', () => {

expect(screen.getByText('en')).toBeDefined()
expect(screen.getByText('it')).toBeDefined()
expect(screen.getByText('zh')).toBeDefined()
})
})
7 changes: 4 additions & 3 deletions src/helpers/config/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type { I18nLocale } from 'types/i18n'

export const defaultLocale = 'en'

export const locales = [defaultLocale, 'it'] as const
export const locales = [defaultLocale, 'it', 'zh'] as const

export const locales_codes: Record<I18nLocale, string> = {
export const locales_regional_codes: Record<I18nLocale, string> = {
en: 'en_GB',
it: 'it_IT'
it: 'it_IT',
zh: 'zh_CN'
}

export const I18N_COOKIE_NAME = 'NEXT_I18N_CURRENT_LOCALE'
Expand Down

0 comments on commit cf05821

Please sign in to comment.