mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 23:33:15 -05:00
[I18N] Allow custom repo size format
Following https://codeberg.org/forgejo/forgejo/pulls/2528#issuecomment-1721846 - simplify the code - allow to have custom format in translations - provide proper Russian translation because test depends on it
This commit is contained in:
parent
7e575603ee
commit
2f38c2220f
4 changed files with 6 additions and 11 deletions
|
@ -234,6 +234,7 @@ type SizeDetail struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SizeDetails forms a struct with various size details about repository
|
// SizeDetails forms a struct with various size details about repository
|
||||||
|
// Note: SizeDetailsString below expects it to have 2 entries
|
||||||
func (repo *Repository) SizeDetails() []SizeDetail {
|
func (repo *Repository) SizeDetails() []SizeDetail {
|
||||||
sizeDetails := []SizeDetail{
|
sizeDetails := []SizeDetail{
|
||||||
{
|
{
|
||||||
|
@ -250,16 +251,8 @@ func (repo *Repository) SizeDetails() []SizeDetail {
|
||||||
|
|
||||||
// SizeDetailsString returns a concatenation of all repository size details as a string
|
// SizeDetailsString returns a concatenation of all repository size details as a string
|
||||||
func (repo *Repository) SizeDetailsString(locale translation.Locale) string {
|
func (repo *Repository) SizeDetailsString(locale translation.Locale) string {
|
||||||
var str strings.Builder
|
|
||||||
sizeDetails := repo.SizeDetails()
|
sizeDetails := repo.SizeDetails()
|
||||||
for i, detail := range sizeDetails {
|
return locale.TrString("repo.size_format", sizeDetails[0].Name, locale.TrSize(sizeDetails[0].Size), sizeDetails[1].Name, locale.TrSize(sizeDetails[1].Size))
|
||||||
if i > 0 {
|
|
||||||
// TODO: use semicolon if decimal point of user localization is a comma
|
|
||||||
str.WriteString(", ")
|
|
||||||
}
|
|
||||||
str.WriteString(fmt.Sprintf("%s: %s", detail.Name, locale.TrSize(detail.Size)))
|
|
||||||
}
|
|
||||||
return str.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) LogString() string {
|
func (repo *Repository) LogString() string {
|
||||||
|
|
|
@ -1011,6 +1011,7 @@ owner_helper = Some organizations may not show up in the dropdown due to a maxim
|
||||||
repo_name = Repository name
|
repo_name = Repository name
|
||||||
repo_name_helper = Good repository names use short, memorable and unique keywords.
|
repo_name_helper = Good repository names use short, memorable and unique keywords.
|
||||||
repo_size = Repository Size
|
repo_size = Repository Size
|
||||||
|
size_format = %[1]s: %[2]s, %[3]s: %[4]s
|
||||||
template = Template
|
template = Template
|
||||||
template_select = Select a template.
|
template_select = Select a template.
|
||||||
template_helper = Make repository a template
|
template_helper = Make repository a template
|
||||||
|
|
|
@ -993,6 +993,7 @@ owner_helper=Некоторые организации могут не отоб
|
||||||
repo_name=Название репозитория
|
repo_name=Название репозитория
|
||||||
repo_name_helper=Лучшие названия репозиториев состоят из коротких, легко запоминаемых и уникальных ключевых слов.
|
repo_name_helper=Лучшие названия репозиториев состоят из коротких, легко запоминаемых и уникальных ключевых слов.
|
||||||
repo_size=Размер репозитория
|
repo_size=Размер репозитория
|
||||||
|
size_format = `%[1]s: %[2]s; %[3]s: %[4]s`
|
||||||
template=Шаблон
|
template=Шаблон
|
||||||
template_select=Выбрать шаблон.
|
template_select=Выбрать шаблон.
|
||||||
template_helper=Сделать репозиторий шаблоном
|
template_helper=Сделать репозиторий шаблоном
|
||||||
|
|
|
@ -87,7 +87,7 @@ func TestDataSizeTranslation(t *testing.T) {
|
||||||
fullSize, exists := repo.Attr("data-tooltip-content")
|
fullSize, exists := repo.Attr("data-tooltip-content")
|
||||||
assert.True(t, exists)
|
assert.True(t, exists)
|
||||||
fullSize = noDigits.ReplaceAllString(fullSize, "")
|
fullSize = noDigits.ReplaceAllString(fullSize, "")
|
||||||
assert.Equal(t, "git: КиБ, lfs: Б", fullSize)
|
assert.Equal(t, "git: КиБ; lfs: Б", fullSize)
|
||||||
|
|
||||||
// Check if file sizes are correclty translated
|
// Check if file sizes are correclty translated
|
||||||
testFileSizeTranslated(t, session, path.Join(testUser, testRepoName, "src/branch/main/137byteFile.txt"), "137 Б")
|
testFileSizeTranslated(t, session, path.Join(testUser, testRepoName, "src/branch/main/137byteFile.txt"), "137 Б")
|
||||||
|
|
Loading…
Reference in a new issue