Skip to content

Commit

Permalink
fix(i18n): Sync forked loadLanguage() from SILE v0.15.7
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Dec 12, 2024
1 parent ff173e8 commit dd872ab
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/casile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ local parseSize = function (size)
return SILE.types.length(size):absolute().length
end

local loadonce = {}

function package:_init (_)
base._init(self)

Expand Down Expand Up @@ -171,10 +169,10 @@ function package:_init (_)
SILE.languageSupport.loadLanguage = function (language)
language = language or SILE.settings:get("document.language")
language = cldr.locales[language] and language or "und"
if loadonce[language] then
if SILE.scratch.loaded_languages[language] then
return
end
loadonce[language] = true
SILE.scratch.loaded_languages[language] = true
local langresource = string.format("languages.%s", language)
local gotlang, lang = pcall(require, langresource)
if not gotlang then
Expand All @@ -185,8 +183,12 @@ function package:_init (_)
)
)
end
local ftlresource = string.format("i18n.%s", language)
local ftlresource = string.format("languages.%s.messages", language)
SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
-- This needs to be set so that we load localizations into the right bundle,
-- but this breaks the sync enabled by the hook in the document.language
-- setting, so we want to set it back when we're done.
local original_language = fluent:get_locale()
fluent:set_locale(language)
local gotftl, ftl = pcall(require, ftlresource)
local ftlresource2 = string.format("assets.%s-%s.casile", language, string.upper(language))
Expand All @@ -203,6 +205,7 @@ function package:_init (_)
if type(lang) == "table" and lang.init then
lang.init()
end
fluent:set_locale(original_language)
end
end

Expand Down

0 comments on commit dd872ab

Please sign in to comment.