mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
add syriac, hindi, add default language and direction maps based on script.
This commit is contained in:
BIN
fonts/NotoSansSyriac.ttf
Normal file
BIN
fonts/NotoSansSyriac.ttf
Normal file
Binary file not shown.
@@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/pemistahl/lingua-go"
|
"github.com/pemistahl/lingua-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nSupportedScripts = 12
|
const nSupportedScripts = 13
|
||||||
|
|
||||||
var (
|
var (
|
||||||
supportedScripts = [nSupportedScripts]language.Script{
|
supportedScripts = [nSupportedScripts]language.Script{
|
||||||
@@ -35,12 +35,45 @@ var (
|
|||||||
language.Javanese,
|
language.Javanese,
|
||||||
language.Han,
|
language.Han,
|
||||||
language.Hangul,
|
language.Hangul,
|
||||||
|
language.Syriac,
|
||||||
}
|
}
|
||||||
|
|
||||||
detector lingua.LanguageDetector
|
detector lingua.LanguageDetector
|
||||||
scriptRanges []ScriptRange
|
scriptRanges []ScriptRange
|
||||||
fontMap [nSupportedScripts]font.Face
|
fontMap [nSupportedScripts]font.Face
|
||||||
emojiFont font.Face
|
emojiFont font.Face
|
||||||
|
|
||||||
|
defaultLanguageMap = [nSupportedScripts]language.Language{
|
||||||
|
"en-us",
|
||||||
|
"en-us",
|
||||||
|
"ja",
|
||||||
|
"ja",
|
||||||
|
"he",
|
||||||
|
"th",
|
||||||
|
"ar",
|
||||||
|
"hi",
|
||||||
|
"bn",
|
||||||
|
"jv",
|
||||||
|
"zh",
|
||||||
|
"ko",
|
||||||
|
"syr",
|
||||||
|
}
|
||||||
|
|
||||||
|
directionMap = [nSupportedScripts]di.Direction{
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionRTL,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionRTL,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionLTR,
|
||||||
|
di.DirectionRTL,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScriptRange struct {
|
type ScriptRange struct {
|
||||||
@@ -60,6 +93,7 @@ func initializeImageDrawingStuff() error {
|
|||||||
lingua.Hebrew,
|
lingua.Hebrew,
|
||||||
lingua.Arabic,
|
lingua.Arabic,
|
||||||
lingua.Bengali,
|
lingua.Bengali,
|
||||||
|
lingua.Hindi,
|
||||||
lingua.Korean,
|
lingua.Korean,
|
||||||
).WithLowAccuracyMode().Build()
|
).WithLowAccuracyMode().Build()
|
||||||
|
|
||||||
@@ -168,28 +202,26 @@ func getLanguageAndScriptAndDirectionAndFont(paragraph []rune) (
|
|||||||
var face font.Face
|
var face font.Face
|
||||||
var idx int
|
var idx int
|
||||||
for l := 0; l < nLetters; l++ {
|
for l := 0; l < nLetters; l++ {
|
||||||
idx := lookupScript(paragraph[l])
|
rnidx := lookupScript(paragraph[l])
|
||||||
ranking[idx]++
|
ranking[rnidx]++
|
||||||
if idx > 0 && l > threshold && ranking[idx] > threshold {
|
if idx > 0 && l > threshold && ranking[rnidx] > threshold {
|
||||||
script = supportedScripts[idx]
|
idx = rnidx
|
||||||
face = fontMap[idx]
|
goto gotScriptIndex
|
||||||
goto gotScript
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
idx = maxIndex(ranking[:])
|
idx = maxIndex(ranking[:])
|
||||||
|
|
||||||
|
gotScriptIndex:
|
||||||
script = supportedScripts[idx]
|
script = supportedScripts[idx]
|
||||||
face = fontMap[idx]
|
face = fontMap[idx]
|
||||||
|
direction := directionMap[idx]
|
||||||
gotScript:
|
|
||||||
direction := di.DirectionLTR
|
|
||||||
if script == language.Arabic {
|
|
||||||
direction = di.DirectionRTL
|
|
||||||
}
|
|
||||||
|
|
||||||
lng := language.Language("en-us")
|
lng := language.Language("en-us")
|
||||||
lang, ok := detector.DetectLanguageOf(string(paragraph))
|
lang, ok := detector.DetectLanguageOf(string(paragraph))
|
||||||
if ok {
|
if ok {
|
||||||
lng = language.Language(lang.IsoCode639_1().String())
|
lng = language.Language(lang.IsoCode639_1().String())
|
||||||
|
} else {
|
||||||
|
lng = defaultLanguageMap[idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
return lng, script, direction, face
|
return lng, script, direction, face
|
||||||
|
|||||||
Reference in New Issue
Block a user