11// Copyright 2024 The Forgejo Authors. All rights reserved.
2- // SPDX-License-Identifier: MIT
3-
2+ // SPDX-License-Identifier: GPL-3.0-or-later
43package integration
54
65import (
@@ -13,13 +12,37 @@ import (
1312
1413 "forgejo.org/models/unittest"
1514 user_model "forgejo.org/models/user"
15+ "forgejo.org/modules/translation/i18n"
1616 files_service "forgejo.org/services/repository/files"
1717 "forgejo.org/tests"
1818
1919 "github.com/PuerkitoBio/goquery"
2020 "github.com/stretchr/testify/assert"
2121)
2222
23+ func TestMissingTranslationHandling (t * testing.T ) {
24+ // Currently new languages can only be added to localestore via AddLocaleByIni
25+ // so this line is here to make the other one work. When INI locales are removed,
26+ // it will not be needed by this test.
27+ i18n .DefaultLocales .AddLocaleByIni ("fun" , "Funlang" , nil , []byte ("" ), nil )
28+
29+ // Add a testing locale to the store
30+ i18n .DefaultLocales .AddToLocaleFromJSON ("fun" , []byte (`{
31+ "meta.last_line": "This language only has one line that is never used by the UI. It will never have a translation for incorrect_root_url"
32+ }` ))
33+
34+ // Get "fun" locale, make sure it's available
35+ funLocale , found := i18n .DefaultLocales .Locale ("fun" )
36+ assert .True (t , found )
37+
38+ // Get translation for a string that this locale doesn't have
39+ s := funLocale .TrString ("incorrect_root_url" )
40+
41+ // Verify fallback to English
42+ assert .True (t , strings .HasPrefix (s , "This Forgejo instance" ))
43+ }
44+
45+ // TestDataSizeTranslation is a test for usage of TrSize in file size display
2346func TestDataSizeTranslation (t * testing.T ) {
2447 onGiteaRun (t , func (t * testing.T , giteaURL * url.URL ) {
2548 testUser := "user2"
@@ -103,14 +126,14 @@ func testFileSizeTranslated(t *testing.T, session *TestSession, filePath, correc
103126 resp := session .MakeRequest (t , req , http .StatusOK )
104127
105128 // Check if file size is translated
106- sizeCorrent := false
129+ sizeCorrect := false
107130 fileInfo := NewHTMLParser (t , resp .Body ).Find (".file-info .file-info-entry" )
108131 fileInfo .Each (func (i int , info * goquery.Selection ) {
109132 infoText := strings .TrimSpace (info .Text ())
110133 if infoText == correctSize {
111- sizeCorrent = true
134+ sizeCorrect = true
112135 }
113136 })
114137
115- assert .True (t , sizeCorrent )
138+ assert .True (t , sizeCorrect )
116139}
0 commit comments