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

sile-typesetter / sile / 9400954821

06 Jun 2024 11:12AM UTC coverage: 61.625% (-11.6%) from 73.209%
9400954821

push

github

web-flow
Merge pull request #2041 from alerque/keep-space-after-envs

2 of 30 new or added lines in 2 files covered. (6.67%)

1933 existing lines in 67 files now uncovered.

10613 of 17222 relevant lines covered (61.62%)

2870.98 hits per line

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

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

4
local loadkit = require("loadkit")
145✔
5
local cldr = require("cldr")
145✔
6

7
loadkit.register("ftl", function (file)
290✔
8
   local contents = assert(file:read("*a"))
170✔
9
   file:close()
170✔
10
   return assert(fluent:add_messages(contents))
340✔
11
end)
12

13
local loadonce = {}
145✔
14

15
SILE.languageSupport = {
145✔
16
   languages = {},
145✔
17
   loadLanguage = function (language)
18
      language = language or SILE.settings:get("document.language")
6,241✔
19
      language = cldr.locales[language] and language or "und"
6,241✔
20
      if loadonce[language] then
6,241✔
21
         return
6,071✔
22
      end
23
      loadonce[language] = true
170✔
24
      local langresource = string.format("languages.%s", language)
170✔
25
      local gotlang, lang = pcall(require, langresource)
170✔
26
      if not gotlang then
170✔
27
         SU.warn(
2✔
28
            ("Unable to load language feature support (e.g. hyphenation rules) for %s: %s"):format(
2✔
29
               language,
1✔
30
               lang:gsub(":.*", "")
1✔
31
            )
32
         )
33
      end
34
      local ftlresource = string.format("i18n.%s", language)
170✔
35
      SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
170✔
36
      fluent:set_locale(language)
170✔
37
      local gotftl, ftl = pcall(require, ftlresource)
170✔
38
      if not gotftl then
170✔
UNCOV
39
         SU.warn(
×
UNCOV
40
            ("Unable to load localized strings (e.g. table of contents header text) for %s: %s"):format(
×
41
               language,
UNCOV
42
               ftl:gsub(":.*", "")
×
43
            )
44
         )
45
      end
46
      if type(lang) == "table" and lang.init then
170✔
47
         lang.init()
2✔
48
      end
49
   end,
50
}
145✔
51

52
SILE.registerCommand("language", function (options, content)
290✔
53
   local main = SU.required(options, "main", "language setting")
10✔
54
   SILE.languageSupport.loadLanguage(main)
10✔
55
   if content[1] then
10✔
56
      SILE.settings:temporarily(function ()
4✔
57
         SILE.settings:set("document.language", main)
2✔
58
         SILE.process(content)
2✔
59
      end)
60
   else
61
      SILE.settings:set("document.language", main)
8✔
62
   end
63
end, nil, nil, true)
155✔
64

65
SILE.registerCommand("fluent", function (options, content)
290✔
66
   local key = content[1]
3✔
67
   local locale = options.locale or SILE.settings:get("document.language")
3✔
68
   SU.debug("fluent", "Looking for", key, "in", locale)
3✔
69
   local entry
70
   if key then
3✔
71
      fluent:set_locale(locale)
3✔
72
      entry = fluent:get_message(key)
6✔
73
   else
74
      SU.warn("Fluent localization function called without passing a valid message id")
×
75
   end
76
   local message
77
   if entry then
3✔
78
      message = entry:format(options)
6✔
79
   else
80
      SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
81
      fluent:set_locale("und")
×
82
      entry = fluent:get_message(key)
×
83
      if entry then
×
84
         message = entry:format(options)
×
85
      end
86
      fluent:set_locale(locale)
×
87
   end
88
   SILE.processString(("<sile>%s</sile>"):format(message), "xml")
3✔
89
end, nil, nil, true)
148✔
90

91
SILE.registerCommand("ftl", function (options, content)
290✔
92
   local locale = options.locale or SILE.settings:get("document.language")
1✔
93
   SU.debug("fluent", "Loading message(s) into locale", locale)
1✔
94
   fluent:set_locale(locale)
1✔
95
   if options.src then
1✔
96
      fluent:load_file(options.src, locale)
×
97
   elseif SU.ast.hasContent(content) then
2✔
98
      local input = content[1]
1✔
99
      fluent:add_messages(input, locale)
1✔
100
   end
101
end, nil, nil, true)
146✔
102

103
require("languages.unicode")
145✔
104

105
-- The following languages neither have hyphenation nor specific
106
-- language support at present. This code is here to suppress warnings.
107
SILE.hyphenator.languages.ar = { patterns = {} }
145✔
108
SILE.hyphenator.languages.bo = { patterns = {} }
145✔
109
SILE.hyphenator.languages.sd = { patterns = {} }
145✔
110
SILE.hyphenator.languages.ur = { patterns = {} }
145✔
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

© 2025 Coveralls, Inc