From a8aa336f4055592b638ab8a673d45a67dc23aad4 Mon Sep 17 00:00:00 2001
From: Seya <31957516+sglkc@users.noreply.github.com>
Date: Thu, 4 Apr 2024 14:57:31 +0700
Subject: [PATCH] feat(romanization): add any language
fix(romanization): converted lyrics doesn't update on language change
docs: update README.md
---
README.md | 25 ++++++++++++++++---------
package.json | 2 +-
src/popup/form.tsx | 1 +
src/services/options.ts | 2 +-
src/web/romanization.ts | 4 +++-
src/web/romanizations/any.ts | 13 +++++++++++++
6 files changed, 35 insertions(+), 12 deletions(-)
create mode 100644 src/web/romanizations/any.ts
diff --git a/README.md b/README.md
index 0e9fff6..96b9b8e 100644
--- a/README.md
+++ b/README.md
@@ -15,12 +15,9 @@
ยท
Request a Feature
- 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*
@@ -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.
@@ -171,6 +172,12 @@ Library used: [pinyin-pro](https://www.npmjs.com/package/pinyin-pro)
+### 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
diff --git a/package.json b/package.json
index ceffdc3..5220668 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/popup/form.tsx b/src/popup/form.tsx
index 3d0adf7..f5e0f40 100644
--- a/src/popup/form.tsx
+++ b/src/popup/form.tsx
@@ -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' },
]
},
{
diff --git a/src/services/options.ts b/src/services/options.ts
index f605199..9838125 100644
--- a/src/services/options.ts
+++ b/src/services/options.ts
@@ -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'
diff --git a/src/web/romanization.ts b/src/web/romanization.ts
index 765a6c4..f5b2d38 100644
--- a/src/web/romanization.ts
+++ b/src/web/romanization.ts
@@ -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
@@ -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
- 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
diff --git a/src/web/romanizations/any.ts b/src/web/romanizations/any.ts
new file mode 100644
index 0000000..3b34b70
--- /dev/null
+++ b/src/web/romanizations/any.ts
@@ -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;