Skip to content

Commit

Permalink
Add Indonesian Dictionary (#845)
Browse files Browse the repository at this point in the history
* Indonesian

json来源:https://github.com/fireindark707/indonesian-common-words/blob/main/dictionary.json

* 补soundResource.ts的id项

* feat: add indonesian pron

---------

Co-authored-by: Kai <[email protected]>
  • Loading branch information
zhuaiyi and RealKai42 authored Sep 9, 2024
1 parent c399dc8 commit 78cac4d
Show file tree
Hide file tree
Showing 8 changed files with 18,266 additions and 8 deletions.
18,224 changes: 18,224 additions & 0 deletions public/dicts/Indonesian.json

Large diffs are not rendered by default.

Binary file added src/assets/flags/id.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/hooks/usePronunciation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useSound from 'use-sound'
import type { HookOptions } from 'use-sound/dist/types'

const pronunciationApi = 'https://dict.youdao.com/dictvoice?audio='
export function generateWordSoundSrc(word: string, pronunciation: Exclude<PronunciationType, false>) {
export function generateWordSoundSrc(word: string, pronunciation: Exclude<PronunciationType, false>): string {
switch (pronunciation) {
case 'uk':
return `${pronunciationApi}${word}&type=1`
Expand All @@ -27,6 +27,10 @@ export function generateWordSoundSrc(word: string, pronunciation: Exclude<Pronun
case 'hapin':
case 'kk':
return `${pronunciationApi}${word}&le=ru` // 有道不支持哈萨克语, 暂时用俄语发音兜底
case 'id':
return `${pronunciationApi}${word}&le=id`
default:
return ''
}
}

Expand Down Expand Up @@ -75,6 +79,8 @@ export function usePrefetchPronunciationSound(word: string | undefined) {
if (!word) return

const soundUrl = generateWordSoundSrc(word, pronunciationConfig.type)
if (soundUrl === '') return

const head = document.head
const isPrefetch = (Array.from(head.querySelectorAll('link[href]')) as HTMLLinkElement[]).some((el) => el.href === soundUrl)

Expand Down
2 changes: 2 additions & 0 deletions src/pages/Gallery-N/LanguageTabSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GalleryContext } from '.'
import codeFlag from '@/assets/flags/code.png'
import deFlag from '@/assets/flags/de.png'
import enFlag from '@/assets/flags/en.png'
import idFlag from '@/assets/flags/id.png'
import jpFlag from '@/assets/flags/ja.png'
import kkFlag from '@/assets/flags/kk.png'
import type { LanguageCategoryType } from '@/typings'
Expand All @@ -19,6 +20,7 @@ const options: LanguageTabOption[] = [
{ id: 'ja', name: '日语', flag: jpFlag },
{ id: 'de', name: '德语', flag: deFlag },
{ id: 'kk', name: '哈萨克语', flag: kkFlag },
{ id: 'id', name: '印尼语', flag: idFlag },
{ id: 'code', name: 'Code', flag: codeFlag },
]

Expand Down
16 changes: 16 additions & 0 deletions src/resources/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3433,6 +3433,21 @@ const kazakhHapinDicts: DictionaryResource[] = [
},
]

//印尼语高频词汇
const indonesianDicts: DictionaryResource[] = [
{
id: 'indonesian_highFrequency_3043',
name: '印尼语高频词汇',
description: '印尼语常用单词及中文解释',
category: '印尼语',
tags: ['基础'],
url: '/dicts/Indonesian.json',
length: 3043,
language: 'id',
languageCategory: 'id',
},
]

/**
* Built-in dictionaries in an array.
* Why arrays? Because it keeps the order across browsers.
Expand All @@ -3445,6 +3460,7 @@ export const dictionaryResources: DictionaryResource[] = [
...japaneseExam,
...germanExam,
...kazakhHapinDicts,
...indonesianDicts,

// {
// id: 'zhtest',
Expand Down
9 changes: 9 additions & 0 deletions src/resources/soundResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ export const LANG_PRON_MAP: LanguagePronunciationMap = {
},
],
},
id: {
defaultPronIndex: 0,
pronunciation: [
{
name: '印尼语',
pron: 'id',
},
],
},
}
9 changes: 5 additions & 4 deletions src/typings/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * from './resource'

export type PronunciationType = 'us' | 'uk' | 'romaji' | 'zh' | 'ja' | 'de' | 'hapin' | 'kk'
export type PhoneticType = 'us' | 'uk' | 'romaji' | 'zh' | 'ja' | 'de' | 'hapin' | 'kk'
export type LanguageType = 'en' | 'romaji' | 'zh' | 'ja' | 'code' | 'de' | 'kk' | 'hapin'
export type LanguageCategoryType = 'en' | 'ja' | 'de' | 'code' | 'kk'
export type PronunciationType = 'us' | 'uk' | 'romaji' | 'zh' | 'ja' | 'de' | 'hapin' | 'kk' | 'id'
export type PhoneticType = 'us' | 'uk' | 'romaji' | 'zh' | 'ja' | 'de' | 'hapin' | 'kk' | 'id'
export type LanguageType = 'en' | 'romaji' | 'zh' | 'ja' | 'code' | 'de' | 'kk' | 'hapin' | 'id'
export type LanguageCategoryType = 'en' | 'ja' | 'de' | 'code' | 'kk' | 'id'

type Pronunciation2PhoneticMap = Record<PronunciationType, PhoneticType>

Expand All @@ -16,6 +16,7 @@ export const PRONUNCIATION_PHONETIC_MAP: Pronunciation2PhoneticMap = {
de: 'de',
hapin: 'hapin',
kk: 'kk',
id: 'id',
}

export type Word = {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2740,9 +2740,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001449, caniuse-lite@^1.0.30001464:
version "1.0.30001489"
resolved "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001489.tgz"
integrity sha512-x1mgZEXK8jHIfAxm+xgdpHpk50IN3z3q3zP261/WS+uvePxW8izXuCu6AHz0lkuYTlATDehiZ/tNyYBdSQsOUQ==
version "1.0.30001655"
resolved "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001655.tgz"
integrity sha512-jRGVy3iSGO5Uutn2owlb5gR6qsGngTw9ZTb4ali9f3glshcNmJ2noam4Mo9zia5P9Dk3jNNydy7vQjuE5dQmfg==

canvas-confetti@^1.6.0:
version "1.6.0"
Expand Down

0 comments on commit 78cac4d

Please sign in to comment.