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

sile-typesetter / sile / 7054606668

01 Dec 2023 01:43AM UTC coverage: 70.141% (-4.2%) from 74.329%
7054606668

push

github

web-flow
Merge 14837a0c3 into a6c229613

11050 of 15754 relevant lines covered (70.14%)

3938.65 hits per line

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

81.43
/core/languages.lua
1
local loadkit = require("loadkit")
90✔
2
local cldr = require("cldr")
90✔
3

4
loadkit.register("ftl", function (file)
180✔
5
  local contents = assert(file:read("*a"))
200✔
6
  file:close()
200✔
7
  return assert(fluent:add_messages(contents))
400✔
8
end)
9

10
local loadonce = {}
90✔
11

12
SILE.languageSupport = {
90✔
13
  languages = {},
90✔
14
  loadLanguage = function (language)
15
    language = language or SILE.settings:get("document.language")
4,700✔
16
    language = cldr.locales[language] and language or "und"
4,700✔
17
    if loadonce[language] then return end
4,700✔
18
    loadonce[language] = true
200✔
19
    local langresource = string.format("languages.%s", language)
200✔
20
    local gotlang, lang = pcall(require, langresource)
200✔
21
    if not gotlang then
200✔
22
      SU.warn(("Unable to load language feature support (e.g. hyphenation rules) for %s: %s")
8✔
23
        :format(language, lang:gsub(":.*", "")))
4✔
24
    end
25
    local ftlresource = string.format("i18n.%s", language)
200✔
26
    SU.debug("fluent", "Loading FTL resource", ftlresource, "into locale", language)
200✔
27
    fluent:set_locale(language)
200✔
28
    local gotftl, ftl = pcall(require, ftlresource)
200✔
29
    if not gotftl then
200✔
30
      SU.warn(("Unable to load localized strings (e.g. table of contents header text) for %s: %s")
×
31
        :format(language, ftl:gsub(":.*", "")))
×
32
    end
33
    if type(lang) == "table" and lang.init then
200✔
34
      lang.init()
6✔
35
    end
36
  end
37
}
90✔
38

39
SILE.registerCommand("language", function (options, content)
180✔
40
  local main = SU.required(options, "main", "language setting")
11✔
41
  SILE.languageSupport.loadLanguage(main)
11✔
42
  if content[1] then
11✔
43
    SILE.settings:temporarily(function ()
×
44
      SILE.settings:set("document.language", main)
×
45
      SILE.process(content)
×
46
    end)
47
  else
48
    SILE.settings:set("document.language", main)
11✔
49
  end
50
end, nil, nil, true)
101✔
51

52
SILE.registerCommand("fluent", function (options, content)
180✔
53
  local key = content[1]
7✔
54
  local locale = options.locale or SILE.settings:get("document.language")
7✔
55
  SU.debug("fluent", "Looking for", key, "in", locale)
7✔
56
  local entry
57
  if key then
7✔
58
    fluent:set_locale(locale)
7✔
59
    entry = fluent:get_message(key)
14✔
60
  else
61
    SU.warn("Fluent localization function called without passing a valid message id")
×
62
  end
63
  local message
64
  if entry then
7✔
65
    message = entry:format(options)
14✔
66
  else
67
    SU.warn(string.format("No localized message for %s found in locale %s", key, locale))
×
68
    fluent:set_locale('und')
×
69
    entry = fluent:get_message(key)
×
70
    if entry then
×
71
      message = entry:format(options)
×
72
    end
73
    fluent:set_locale(locale)
×
74
  end
75
  SILE.processString(("<sile>%s</sile>"):format(message), "xml")
7✔
76
end, nil, nil, true)
97✔
77

78
SILE.registerCommand("ftl", function (options, content)
180✔
79
  local locale = options.locale or SILE.settings:get("document.language")
1✔
80
  SU.debug("fluent", "Loading message(s) into locale", locale)
1✔
81
  fluent:set_locale(locale)
1✔
82
  if options.src then
1✔
83
    fluent:load_file(options.src, locale)
×
84
  elseif SU.hasContent(content) then
2✔
85
    local input = content[1]
1✔
86
    fluent:add_messages(input, locale)
1✔
87
  end
88
end, nil, nil, true)
91✔
89

90
require("languages.unicode")
90✔
91

92
-- The following languages neither have hyphenation nor specific
93
-- language support at present. This code is here to suppress warnings.
94
SILE.hyphenator.languages.ar = { patterns = {} }
90✔
95
SILE.hyphenator.languages.bo = { patterns = {} }
90✔
96
SILE.hyphenator.languages.sd = { patterns = {} }
90✔
97
SILE.hyphenator.languages.ur = { patterns = {} }
90✔
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