Skip to content

Commit

Permalink
feat(romanization): add any language
Browse files Browse the repository at this point in the history
fix(romanization): converted lyrics doesn't update on language change
docs: update README.md
  • Loading branch information
sglkc committed Apr 4, 2024
1 parent c062555 commit a8aa336
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
<strong>·</strong>
<a href="https://github.com/sglkc/moegi/issues">Request a Feature</a>

Features lyrics translation for over 100 languages powered by Google Translate, \
Cyrillic lyrics romanization for Russian and Ukrainian language,
Chinese lyrics romanization to pinyin in text or ruby format,
Korean lyrics romanization with Revised, McCune, and Yale system, \
Japanese lyrics romanization to romaji, hiragana, and katakana in different formats including furigana! \
*Tested on Google Chrome (122.0.6261.111) and Brave Browser (122.1.63.169) on Linux*
Features lyrics translation for over 100 languages powered by Google Translate and \
romanization for Chinese, Korean, Japanese, Cyrillic, and many more non-latin scripts! \
*Tested on Google Chrome (122.0.6261.111) and Brave Browser (123.1.64.113) on Linux*

<br />
</div>
Expand Down Expand Up @@ -79,9 +76,13 @@ Note that translations are not accurate and should not be used literally! [Read

### Romanization

There are currently supported languages:
- [Japanese](#japanese)
- [Korean](#korean)
Mainly supported languages:
1. [Japanese](#japanese)
2. [Korean](#korean)
3. [Chinese](#chinese)
4. [Cyrillic](#cyrillic)

Other than that, use [Anything else](#any).

Romanize lyrics that has the selected language's characters, if none then it will skip to the next line.

Expand Down Expand Up @@ -171,6 +172,12 @@ Library used: [pinyin-pro](https://www.npmjs.com/package/pinyin-pro)

</details>

### Any

Library used: [any-ascii](https://github.com/anyascii/anyascii)

Provides a lot of conversions at the cost of accuracy, read more from the package repository.

## Development

### Prerequisites
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A Spotify lyrics extension for styling, translation, and romanization",
"homepage": "https://github.com/sglkc/moegi",
"private": true,
"version": "1.2.0",
"version": "1.2.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
1 change: 1 addition & 0 deletions src/popup/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function Form() {
{ text: 'Korean', value: 'korean' },
{ text: 'Cyrillic', value: 'cyrillic' },
{ text: 'Chinese', value: 'chinese' },
{ text: 'Anything else', value: 'any' },
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/services/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type MoegiOptions = {
translation_size: number
languageTarget: TranslationLanguage
romanization: boolean
romanization_lang: 'japanese' | 'korean' | 'cyrillic' | 'chinese'
romanization_lang: 'japanese' | 'korean' | 'cyrillic' | 'chinese' | 'any'
romanization_size: number
chinese_ruby: boolean
cyrillic_lang: 'ru' | 'uk'
Expand Down
4 changes: 3 additions & 1 deletion src/web/romanization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const romanizations = {
korean: import('./romanizations/korean'),
cyrillic: import('./romanizations/cyrillic'),
chinese: import('./romanizations/chinese'),
any: import('./romanizations/any'),
}

// Convert lyric lines using hangul-romanization if they have any Korean characters
Expand Down Expand Up @@ -46,7 +47,8 @@ async function applyRomanization(event: WindowEventMap['moegioptions']) {

// Check if romanization should update or not based on updateKeys
const updateDetail = Object.keys(event.detail ?? {}) as Array<MoegiOptionsKey>
const shouldUpdate = updateDetail.find(key => language.updateKeys.includes(key))
const shouldUpdate = updateDetail.includes('romanization_lang')
|| updateDetail.find(key => language.updateKeys.includes(key))

if ((event.type === 'moegioptions') && !shouldUpdate) return

Expand Down
13 changes: 13 additions & 0 deletions src/web/romanizations/any.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import anyAscii from 'any-ascii';
import { Romanization } from '../romanization';

const AnyAscii: Romanization = {
name: 'Any',
language: 'any',
updateKeys: [],
check: (text) => (/([\p{L}\p{N}\s])+/u).test(text),
convert: async (text, _options) => anyAscii(text),
}


export default AnyAscii;

0 comments on commit a8aa336

Please sign in to comment.