mirror of
https://gitea.com/gitea/gitea-mirror.git
synced 2026-03-20 03:40:27 +00:00
@@ -348,23 +348,6 @@ func deprecatedSettingDB(rootCfg ConfigProvider, oldSection, oldKey string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigProviderForLocale loads locale configuration from source and others. "string" if for a local file path, "[]byte" is for INI content
|
|
||||||
func NewConfigProviderForLocale(source any, others ...any) (ConfigProvider, error) {
|
|
||||||
iniFile, err := ini.LoadSources(ini.LoadOptions{
|
|
||||||
IgnoreInlineComment: true,
|
|
||||||
UnescapeValueCommentSymbols: true,
|
|
||||||
IgnoreContinuation: true,
|
|
||||||
}, source, others...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to load locale ini: %w", err)
|
|
||||||
}
|
|
||||||
iniFile.BlockMode = false
|
|
||||||
return &iniConfigProvider{
|
|
||||||
ini: iniFile,
|
|
||||||
loadedFromEmpty: true,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ini.PrettyFormat = false
|
ini.PrettyFormat = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,24 +113,6 @@ func TestNewConfigProviderFromFile(t *testing.T) {
|
|||||||
assert.Equal(t, "[foo]\nk1 = a\n\n[bar]\nk1 = b\n", string(bs))
|
assert.Equal(t, "[foo]\nk1 = a\n\n[bar]\nk1 = b\n", string(bs))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewConfigProviderForLocale(t *testing.T) {
|
|
||||||
// load locale from file
|
|
||||||
localeFile := t.TempDir() + "/locale.ini"
|
|
||||||
_ = os.WriteFile(localeFile, []byte(`k1=a`), 0o644)
|
|
||||||
cfg, err := NewConfigProviderForLocale(localeFile)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "a", cfg.Section("").Key("k1").String())
|
|
||||||
|
|
||||||
// load locale from bytes
|
|
||||||
cfg, err = NewConfigProviderForLocale([]byte("k1=foo\nk2=bar"))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "foo", cfg.Section("").Key("k1").String())
|
|
||||||
cfg, err = NewConfigProviderForLocale([]byte("k1=foo\nk2=bar"), []byte("k2=xxx"))
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "foo", cfg.Section("").Key("k1").String())
|
|
||||||
assert.Equal(t, "xxx", cfg.Section("").Key("k2").String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDisableSaving(t *testing.T) {
|
func TestDisableSaving(t *testing.T) {
|
||||||
testFile := t.TempDir() + "/test.ini"
|
testFile := t.TempDir() + "/test.ini"
|
||||||
_ = os.WriteFile(testFile, []byte("k1=a\nk2=b"), 0o644)
|
_ = os.WriteFile(testFile, []byte("k1=a\nk2=b"), 0o644)
|
||||||
|
|||||||
Reference in New Issue
Block a user