-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐉 Homepage language improvements (#295)
* Add language utils * Add new property to schema * Try to predict language for each video * Generate new mappings
- Loading branch information
Showing
6 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 11 additions & 5 deletions
16
db/migrations/1704732670595-Data.js → db/migrations/1707311702202-Data.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import LanguageDetect from 'languagedetect' | ||
|
||
function cleanString(input: string): string { | ||
// Remove symbols, numbers, and emojis | ||
// The regex [\p{P}\p{S}\p{N}\p{M}] matches all kinds of punctuation, symbols, numbers, and mark characters (including emojis) | ||
// \p{P} matches any kind of punctuation character | ||
// \p{S} matches any kind of math symbol, currency sign, or modifier symbol | ||
// \p{N} matches any kind of numeric character in any script | ||
// \p{M} matches characters that are combined with other characters, often used for emojis and diacritics | ||
// The 'u' flag enables Unicode support, allowing the regex to match Unicode characters and properties | ||
const cleanedString = input.replace(/[\p{P}\p{S}\p{N}\p{M}]/gu, '') | ||
return cleanedString.toLowerCase() | ||
} | ||
|
||
const lngDetector = new LanguageDetect() | ||
lngDetector.setLanguageType('iso2') | ||
|
||
// Example usage | ||
export const predictLanguage = (text: string): string | undefined => { | ||
const cleanedText = cleanString(text) | ||
return lngDetector.detect(cleanedText, 1)[0]?.[0] | ||
} |