43 lines
1.3 KiB
Julia
43 lines
1.3 KiB
Julia
|
# Pot import/export functions
|
||
|
|
||
|
is_comment(line; char = r"#") = startswith(line, char)
|
||
|
|
||
|
function readpot(path, lang, name = "base")
|
||
|
lines = readlines(joinpath(path, lang, "LC_MESSAGES", string(name, ".pot")))
|
||
|
filter!(x -> !is_comment(x, char = r"#(?!:)"), lines)
|
||
|
filter!(!isempty, lines)
|
||
|
lines = lines[3:end]
|
||
|
@assert length(lines) % 3 == 0
|
||
|
output = []
|
||
|
for l in 1:3:length(lines)
|
||
|
ref = split(lines[l], "#: ")
|
||
|
msgid = split(lines[l+1], "msgid ")
|
||
|
msgstr = split(lines[l+2], "msgstr ")
|
||
|
@assert length(ref) == 2
|
||
|
@assert length(msgid) == 2
|
||
|
@assert length(msgstr) == 2
|
||
|
id = split(msgid[2], '"')
|
||
|
str = split(msgstr[2], '"')
|
||
|
if length(id) != 3 && l != 1
|
||
|
@warn "Problems with $msgstr $msgid"
|
||
|
continue
|
||
|
end
|
||
|
if isempty(str[2])
|
||
|
continue
|
||
|
end
|
||
|
push!(output, (lang, id[2], str[2], split(ref[2], ":")[1]))
|
||
|
end
|
||
|
output
|
||
|
end
|
||
|
|
||
|
function pot_to_jl(lang, id)
|
||
|
"""@translate "$lang" "$(id[2])" "$(str[2])" """
|
||
|
end
|
||
|
|
||
|
function pot_to_jl(srcpath, destpath, filename, basename)
|
||
|
langs = readdir(srcpath)
|
||
|
content = join([join(readpot(srcpath, lang, basename), "\n")
|
||
|
for lang in langs], "\n\n")
|
||
|
write(joinpath(destpath, string(filename, ".jl")), content)
|
||
|
end
|