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

sile-typesetter / sile / 7232859119

16 Dec 2023 03:49PM UTC coverage: 66.878% (-7.7%) from 74.62%
7232859119

push

github

web-flow
Merge 05d75c2a3 into 8686730e4

0 of 4 new or added lines in 1 file covered. (0.0%)

1201 existing lines in 56 files now uncovered.

10550 of 15775 relevant lines covered (66.88%)

3347.52 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")
71✔
2
local cldr = require("cldr")
71✔
3

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

10
local loadonce = {}
71✔
11

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

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

52
SILE.registerCommand("fluent", function (options, content)
142✔
53
  local key = content[1]
3✔
54
  local locale = options.locale or SILE.settings:get("document.language")
3✔
55
  SU.debug("fluent", "Looking for", key, "in", locale)
3✔
56
  local entry
57
  if key then
3✔
58
    fluent:set_locale(locale)
3✔
59
    entry = fluent:get_message(key)
6✔
60
  else
61
    SU.warn("Fluent localization function called without passing a valid message id")
×
62
  end
63
  local message
64
  if entry then
3✔
65
    message = entry:format(options)
6✔
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")
3✔
76
end, nil, nil, true)
74✔
77

78
SILE.registerCommand("ftl", function (options, content)
142✔
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)
72✔
89

90
require("languages.unicode")
71✔
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 = {} }
71✔
95
SILE.hyphenator.languages.bo = { patterns = {} }
71✔
96
SILE.hyphenator.languages.sd = { patterns = {} }
71✔
97
SILE.hyphenator.languages.ur = { patterns = {} }
71✔
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