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

sile-typesetter / sile / 14334874064

08 Apr 2025 01:31PM UTC coverage: 59.535% (-3.5%) from 63.083%
14334874064

push

github

web-flow
Merge pull request #2259 from Omikhleia/fix-hyphen-minima

Fix hyphen minima logic and update several hyphenation patterns

21 of 34 new or added lines in 14 files covered. (61.76%)

941 existing lines in 51 files now uncovered.

12856 of 21594 relevant lines covered (59.54%)

2362.76 hits per line

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

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

4
local cldr = require("cldr")
131✔
5
local setenv = require("rusile").setenv
131✔
6

7
SILE.scratch.loaded_languages = {}
131✔
8

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

51
SILE.settings:declare({
262✔
52
   parameter = "document.language",
53
   type = "string",
54
   default = "en",
55
   hook = function (language)
56
      SILE.languageSupport.loadLanguage(language)
576✔
57
      fluent:set_locale(language)
576✔
58
      os.setlocale(language)
576✔
59
      setenv("LANG", language)
576✔
60
   end,
61
   help = "Locale for localized language support",
62
})
63

64
SILE.registerCommand("language", function (options, content)
262✔
65
   local main = SU.required(options, "main", "language setting")
9✔
66
   SILE.languageSupport.loadLanguage(main)
9✔
67
   if content[1] then
9✔
UNCOV
68
      SILE.settings:temporarily(function ()
×
UNCOV
69
         SILE.settings:set("document.language", main)
×
UNCOV
70
         SILE.process(content)
×
71
      end)
72
   else
73
      SILE.settings:set("document.language", main)
9✔
74
   end
75
end, nil, nil, true)
140✔
76

77
SILE.registerCommand("fluent", function (options, content)
262✔
78
   local key = content[1]
3✔
79
   local locale = options.locale or SILE.settings:get("document.language")
3✔
80
   local original_locale = fluent:get_locale()
3✔
81
   fluent:set_locale(locale)
3✔
82
   SU.debug("fluent", "Looking for", key, "in", locale)
3✔
83
   local entry
84
   if key then
3✔
85
      entry = fluent:get_message(key)
6✔
86
   else
87
      SU.warn("Fluent localization function called without passing a valid message id")
×
88
   end
89
   local message
90
   if entry then
3✔
91
      message = entry:format(options)
6✔
92
   else
93
      SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
94
      fluent:set_locale("und")
×
95
      entry = fluent:get_message(key)
×
96
      if entry then
×
97
         message = entry:format(options)
×
98
      end
99
   end
100
   fluent:set_locale(original_locale)
3✔
101
   SILE.processString(("<sile>%s</sile>"):format(message), "xml")
3✔
102
end, nil, nil, true)
134✔
103

104
SILE.registerCommand("ftl", function (options, content)
262✔
105
   local original_locale = fluent:get_locale()
1✔
106
   local locale = options.locale or SILE.settings:get("document.language")
1✔
107
   SU.debug("fluent", "Loading message(s) into locale", locale)
1✔
108
   fluent:set_locale(locale)
1✔
109
   if options.src then
1✔
110
      fluent:load_file(options.src, locale)
×
111
   elseif SU.ast.hasContent(content) then
2✔
112
      local input = content[1]
1✔
113
      fluent:add_messages(input, locale)
1✔
114
   end
115
   fluent:set_locale(original_locale)
1✔
116
end, nil, nil, true)
132✔
117

118
require("languages.unicode")
131✔
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