fixed translations in opensearch.xml

This commit is contained in:
partisan 2024-10-25 13:54:29 +02:00
parent 5a4be6dad6
commit 90d3964ca2
12 changed files with 39 additions and 5 deletions

View file

@ -65,6 +65,7 @@ func main() {
// Start automatic update checker, not used now // Start automatic update checker, not used now
//go checkForUpdates() //go checkForUpdates()
InitializeLanguage("en") // Initialize language before generating OpenSearch
generateOpenSearchXML(config) generateOpenSearchXML(config)
go startNodeClient() go startNodeClient()

View file

@ -14,7 +14,7 @@ func InitializeLanguage(siteLanguage string) {
translationsDir := "lang" translationsDir := "lang"
localeDir := filepath.Join(translationsDir, siteLanguage, "LC_MESSAGES") localeDir := filepath.Join(translationsDir, siteLanguage, "LC_MESSAGES")
if _, err := os.Stat(localeDir); os.IsNotExist(err) { if _, err := os.Stat(localeDir); os.IsNotExist(err) {
printWarn("Translation directory for language '%s' does not exist. Using default.", siteLanguage) printWarn("Translation directory for language '%s' not found. Defaulting to English.", siteLanguage)
siteLanguage = "en" // Use default language if not found siteLanguage = "en" // Use default language if not found
localeDir = filepath.Join(translationsDir, siteLanguage, "LC_MESSAGES") localeDir = filepath.Join(translationsDir, siteLanguage, "LC_MESSAGES")
} }
@ -26,6 +26,7 @@ func InitializeLanguage(siteLanguage string) {
// Translate wraps gotext.Get and returns a translated string based on the given key. // Translate wraps gotext.Get and returns a translated string based on the given key.
func Translate(key string, params ...interface{}) string { func Translate(key string, params ...interface{}) string {
if translations == nil { if translations == nil {
printWarn("Translation failed for key '%s'. This may occur if Translate is called before initializing language settings or if the key is missing.", key)
return key // Fallback if translations are not initialized return key // Fallback if translations are not initialized
} }
return translations.Get(key, params...) return translations.Get(key, params...)

View file

@ -40,6 +40,9 @@ msgstr "Site Language"
msgid "search_language" msgid "search_language"
msgstr "Search Language" msgstr "Search Language"
msgid "any_language"
msgstr "Any Language"
msgid "no_results" msgid "no_results"
msgstr "No results found for '%s'. Try different keywords." msgstr "No results found for '%s'. Try different keywords."
@ -189,3 +192,12 @@ msgstr "You are within "
msgid "meters_from_point" msgid "meters_from_point"
msgstr "meters from this point" msgstr "meters from this point"
msgid "opensearch_shortname"
msgstr "QGato Search"
msgid "opensearch_description"
msgstr "QGato - A Privacy-Focused Search Engine"
msgid "opensearch_tags"
msgstr "search, qgato, spitfire"

View file

@ -40,6 +40,9 @@ msgstr "Język strony"
msgid "search_language" msgid "search_language"
msgstr "Język wyszukiwania" msgstr "Język wyszukiwania"
msgid "any_language"
msgstr "Dowolny język"
msgid "no_results" msgid "no_results"
msgstr "Nie znaleziono wyników dla '%s'. Spróbuj innych słów kluczowych." msgstr "Nie znaleziono wyników dla '%s'. Spróbuj innych słów kluczowych."
@ -189,3 +192,12 @@ msgstr "Znajdujesz się w odległości "
msgid "meters_from_point" msgid "meters_from_point"
msgstr "metrów od tego punktu" msgstr "metrów od tego punktu"
msgid "opensearch_shortname"
msgstr "Wyszukiwarka QGato"
msgid "opensearch_description"
msgstr "QGato - Prywatna wyszukiwarka internetowa"
msgid "opensearch_tags"
msgstr "wyszukiwarka, qgato, spitfire"

View file

@ -109,6 +109,13 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
InitializeLanguage(settings.SiteLanguage) InitializeLanguage(settings.SiteLanguage)
// Translate the "Any Language" option after initialization
for i, option := range languageOptions {
if option.Code == "" {
languageOptions[i].Name = Translate("any_language")
}
}
if query == "" { if query == "" {
data := struct { data := struct {
LanguageOptions []LanguageOption LanguageOptions []LanguageOption

View file

@ -21,13 +21,14 @@ type URL struct {
} }
func generateOpenSearchXML(config Config) { func generateOpenSearchXML(config Config) {
baseURL := addProtocol(config.Domain) // Ensure that language is initialized in `main` before calling this function
baseURL := addProtocol(config.Domain)
opensearch := OpenSearchDescription{ opensearch := OpenSearchDescription{
Xmlns: "http://a9.com/-/spec/opensearch/1.1/", Xmlns: "http://a9.com/-/spec/opensearch/1.1/",
ShortName: "QGato", ShortName: Translate("opensearch_shortname"),
Description: "QGato search engine", Description: Translate("opensearch_description"),
Tags: "search, spitfire, qgato", Tags: Translate("opensearch_tags"),
URLs: []URL{ URLs: []URL{
{ {
Type: "text/html", Type: "text/html",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 12 KiB