1
0
mirror of https://github.com/msberends/AMR.git synced 2026-01-11 23:54:34 +01:00

(v3.0.1.9007) fix #246

This commit is contained in:
2026-01-06 23:08:50 +01:00
parent f6e28ac95c
commit cfbbfb4fa5
30 changed files with 628 additions and 444 deletions

View File

@@ -263,20 +263,47 @@ translate_into_language <- function(from,
df_trans$pattern[df_trans$regular_expr == TRUE] <- gsub("$$", "$", df_trans$pattern[df_trans$regular_expr == TRUE], fixed = TRUE)
}
# regex part
lapply(
# starting with longest pattern, since more general translations are shorter, such as 'Group'
order(nchar(df_trans$pattern), decreasing = TRUE),
order(nchar(df_trans$pattern), decreasing = TRUE)[df_trans$regular_expr == TRUE],
function(i) {
from_unique_translated <<- gsub(
pattern = df_trans$pattern[i],
replacement = df_trans[i, lang, drop = TRUE],
x = from_unique_translated,
ignore.case = !df_trans$case_sensitive[i] & df_trans$regular_expr[i],
fixed = !df_trans$regular_expr[i],
perl = df_trans$regular_expr[i]
ignore.case = !df_trans$case_sensitive[i],
fixed = FALSE,
perl = TRUE
)
}
)
# non-regex part
from_unique_translated <- vapply(
FUN.VALUE = character(1),
USE.NAMES = FALSE,
from_unique_translated,
function(x) {
words <- strsplit(x, " ", fixed = TRUE)[[1]]
# print(words)
for (i in seq_along(words)) {
word_trans <- df_trans[[lang]][df_trans$regular_expr == FALSE][match(words[i], df_trans$pattern[df_trans$regular_expr == FALSE])]
if (!is.na(word_trans)) {
words[i] <- word_trans
}
}
words <- paste(words, collapse = " ")
words <- strsplit(x, "/", fixed = TRUE)[[1]]
# print(words)
for (i in seq_along(words)) {
word_trans <- df_trans[[lang]][df_trans$regular_expr == FALSE][match(words[i], df_trans$pattern[df_trans$regular_expr == FALSE])]
if (!is.na(word_trans)) {
words[i] <- word_trans
}
}
paste(words, collapse = " ")
}
)
# force UTF-8 for diacritics
from_unique_translated <- enc2utf8(from_unique_translated)