• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 13971572131

20 Mar 2025 02:18PM UTC coverage: 58.91% (-5.4%) from 64.296%
13971572131

push

github

web-flow
Merge pull request #2087 from jodros/twoside-headers

Declare SILE.scratch.headers in twoside only

2 of 2 new or added lines in 1 file covered. (100.0%)

1120 existing lines in 54 files now uncovered.

12668 of 21504 relevant lines covered (58.91%)

1910.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.75
/core/languages.lua
1
--- SILE language class.
2
-- @interfaces languages
3

4
local cldr = require("cldr")
213✔
5
local loadkit = require("loadkit")
213✔
6
local setenv = require("rusile").setenv
213✔
7

8
loadkit.register("ftl", function (file)
426✔
9
   local contents = assert(file:read("*a"))
360✔
10
   file:close()
360✔
11
   return assert(fluent:add_messages(contents))
720✔
12
end)
13

14
SILE.scratch.loaded_languages = {}
213✔
15

16
SILE.languageSupport = {
213✔
17
   languages = {},
213✔
18
   loadLanguage = function (language)
19
      language = language or SILE.settings:get("document.language")
7,752✔
20
      language = cldr.locales[language] and language or "und"
7,752✔
21
      if SILE.scratch.loaded_languages[language] then
7,752✔
22
         return
7,392✔
23
      end
24
      SILE.scratch.loaded_languages[language] = true
360✔
25
      local langresource = string.format("languages.%s", language)
360✔
26
      local gotlang, lang = pcall(require, langresource)
360✔
27
      if not gotlang then
360✔
UNCOV
28
         SU.warn(
×
UNCOV
29
            ("Unable to load language feature support (e.g. hyphenation rules) for %s: %s"):format(
×
30
               language,
UNCOV
31
               lang:gsub(":.*", "")
×
32
            )
33
         )
34
      end
35
      local ftlresource = string.format("languages.%s.messages", language)
360✔
36
      SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
360✔
37
      -- This needs to be set so that we load localizations into the right bundle,
38
      -- but this breaks the sync enabled by the hook in the document.language
39
      -- setting, so we want to set it back when we're done.
40
      local original_language = fluent:get_locale()
360✔
41
      fluent:set_locale(language)
360✔
42
      local gotftl, ftl = pcall(require, ftlresource)
360✔
43
      if not gotftl then
360✔
UNCOV
44
         SU.warn(
×
UNCOV
45
            ("Unable to load localized strings (e.g. table of contents header text) for %s: %s"):format(
×
46
               language,
UNCOV
47
               ftl:gsub(":.*", "")
×
48
            )
49
         )
50
      end
51
      if type(lang) == "table" and lang.init then
360✔
52
         lang.init()
6✔
53
      end
54
      fluent:set_locale(original_language)
360✔
55
   end,
56
}
213✔
57

58
SILE.settings:declare({
426✔
59
   parameter = "document.language",
60
   type = "string",
61
   default = "en",
62
   hook = function (language)
63
      SILE.languageSupport.loadLanguage(language)
713✔
64
      fluent:set_locale(language)
713✔
65
      os.setlocale(language)
713✔
66
      setenv("LANG", language)
713✔
67
   end,
68
   help = "Locale for localized language support",
69
})
70

71
SILE.registerCommand("language", function (options, content)
426✔
72
   local main = SU.required(options, "main", "language setting")
21✔
73
   SILE.languageSupport.loadLanguage(main)
21✔
74
   if content[1] then
21✔
75
      SILE.settings:temporarily(function ()
4✔
76
         SILE.settings:set("document.language", main)
2✔
77
         SILE.process(content)
2✔
78
      end)
79
   else
80
      SILE.settings:set("document.language", main)
19✔
81
   end
82
end, nil, nil, true)
234✔
83

84
SILE.registerCommand("fluent", function (options, content)
426✔
85
   local key = content[1]
7✔
86
   local locale = options.locale or SILE.settings:get("document.language")
7✔
87
   local original_locale = fluent:get_locale()
7✔
88
   fluent:set_locale(locale)
7✔
89
   SU.debug("fluent", "Looking for", key, "in", locale)
7✔
90
   local entry
91
   if key then
7✔
92
      entry = fluent:get_message(key)
14✔
93
   else
94
      SU.warn("Fluent localization function called without passing a valid message id")
×
95
   end
96
   local message
97
   if entry then
7✔
98
      message = entry:format(options)
14✔
99
   else
100
      SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
101
      fluent:set_locale("und")
×
102
      entry = fluent:get_message(key)
×
103
      if entry then
×
104
         message = entry:format(options)
×
105
      end
106
   end
107
   fluent:set_locale(original_locale)
7✔
108
   SILE.processString(("<sile>%s</sile>"):format(message), "xml")
7✔
109
end, nil, nil, true)
220✔
110

111
SILE.registerCommand("ftl", function (options, content)
426✔
112
   local original_locale = fluent:get_locale()
1✔
113
   local locale = options.locale or SILE.settings:get("document.language")
1✔
114
   SU.debug("fluent", "Loading message(s) into locale", locale)
1✔
115
   fluent:set_locale(locale)
1✔
116
   if options.src then
1✔
117
      fluent:load_file(options.src, locale)
×
118
   elseif SU.ast.hasContent(content) then
2✔
119
      local input = content[1]
1✔
120
      fluent:add_messages(input, locale)
1✔
121
   end
122
   fluent:set_locale(original_locale)
1✔
123
end, nil, nil, true)
214✔
124

125
require("languages.unicode")
213✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc