diff --git a/internal/cliutils/prompt.go b/internal/cliutils/prompt.go index 4173911..19855c6 100644 --- a/internal/cliutils/prompt.go +++ b/internal/cliutils/prompt.go @@ -28,10 +28,8 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/leonelquinteros/gotext" - "gitea.plemya-x.ru/Plemya-x/ALR/internal/config" "gitea.plemya-x.ru/Plemya-x/ALR/internal/db" "gitea.plemya-x.ru/Plemya-x/ALR/internal/pager" - "gitea.plemya-x.ru/Plemya-x/ALR/internal/translations" ) // YesNoPrompt asks the user a yes or no question, using def as the default answer @@ -40,7 +38,7 @@ func YesNoPrompt(ctx context.Context, msg string, interactive, def bool) (bool, var answer bool err := survey.AskOne( &survey.Confirm{ - Message: translations.Translator(ctx).TranslateTo(msg, config.Language(ctx)), + Message: msg, Default: def, }, &answer, @@ -59,8 +57,7 @@ func PromptViewScript(ctx context.Context, script, name, style string, interacti return nil } - scriptPrompt := translations.Translator(ctx).TranslateTo("Would you like to view the build script for", config.Language(ctx)) + " " + name - view, err := YesNoPrompt(ctx, scriptPrompt, interactive, false) + view, err := YesNoPrompt(ctx, gotext.Get("Would you like to view the build script for %s", name), interactive, false) if err != nil { return err } @@ -71,7 +68,7 @@ func PromptViewScript(ctx context.Context, script, name, style string, interacti return err } - cont, err := YesNoPrompt(ctx, "Would you still like to continue?", interactive, false) + cont, err := YesNoPrompt(ctx, gotext.Get("Would you still like to continue?"), interactive, false) if err != nil { return err } @@ -135,7 +132,7 @@ func PkgPrompt(ctx context.Context, options []db.Package, verb string, interacti prompt := &survey.Select{ Options: names, - Message: translations.Translator(ctx).TranslateTo("Choose which package to "+verb, config.Language(ctx)), + Message: gotext.Get("Choose which package to %s", verb), } var choice int @@ -156,7 +153,7 @@ func ChooseOptDepends(ctx context.Context, options []string, verb string, intera prompt := &survey.MultiSelect{ Options: options, - Message: translations.Translator(ctx).TranslateTo("Choose which optional package(s) to install", config.Language(ctx)), + Message: gotext.Get("Choose which optional package(s) to install"), } var choices []int diff --git a/internal/dl/dl.go b/internal/dl/dl.go index a8400bc..75e25d1 100644 --- a/internal/dl/dl.go +++ b/internal/dl/dl.go @@ -219,7 +219,7 @@ func Download(ctx context.Context, opts Options) (err error) { } } - slog.Info("Downloading source", "source", opts.Name, "downloader", d.Name()) + slog.Info(gotext.Get("Downloading source"), "source", opts.Name, "downloader", d.Name()) cacheDir, err = dc.New(ctx, opts.URL) if err != nil { diff --git a/internal/translations/default.pot b/internal/translations/default.pot index 515ff4b..5257adb 100644 --- a/internal/translations/default.pot +++ b/internal/translations/default.pot @@ -105,14 +105,30 @@ msgstr "" msgid "Error removing packages" msgstr "" -#: internal/cliutils/prompt.go:80 +#: internal/cliutils/prompt.go:60 +msgid "Would you like to view the build script for %s" +msgstr "" + +#: internal/cliutils/prompt.go:71 +msgid "Would you still like to continue?" +msgstr "" + +#: internal/cliutils/prompt.go:77 msgid "User chose not to continue after reading script" msgstr "" -#: internal/cliutils/prompt.go:114 +#: internal/cliutils/prompt.go:111 msgid "Error prompting for choice of package" msgstr "" +#: internal/cliutils/prompt.go:135 +msgid "Choose which package to %s" +msgstr "" + +#: internal/cliutils/prompt.go:156 +msgid "Choose which optional package(s) to install" +msgstr "" + #: internal/config/config.go:63 msgid "Error opening config file, using defaults" msgstr "" @@ -178,12 +194,12 @@ msgstr "" msgid "Source updated and linked to destination" msgstr "" -#: internal/logger/log.go:44 -msgid "ERROR" +#: internal/dl/dl.go:222 +msgid "Downloading source" msgstr "" -#: internal/translations/translations.go:52 -msgid "Error creating new translator" +#: internal/logger/log.go:44 +msgid "ERROR" msgstr "" #: list.go:53 @@ -224,6 +240,12 @@ msgstr "" msgid "Compressing package" msgstr "" +#: pkg/build/build.go:312 +msgid "" +"Your system's CPU architecture doesn't match this package. Do you want to " +"build anyway?" +msgstr "" + #: pkg/build/build.go:323 msgid "This package is already installed" msgstr "" @@ -260,6 +282,10 @@ msgstr "" msgid "AutoReq is not implemented for this package format, so it's skiped" msgstr "" +#: pkg/build/build.go:653 +msgid "Would you like to remove the build dependencies?" +msgstr "" + #: pkg/build/build.go:759 msgid "The checksums array must be the same length as sources" msgstr "" diff --git a/internal/translations/files/lure.en.toml b/internal/translations/files/lure.en.toml deleted file mode 100644 index 73bb01f..0000000 --- a/internal/translations/files/lure.en.toml +++ /dev/null @@ -1,174 +0,0 @@ -# This file was originally part of the project "LURE - Linux User REpository", created by Elara Musayelyan. -# It has been modified as part of "ALR - Any Linux Repository" by Евгений Храмов. -# -# ALR - Any Linux Repository -# Copyright (C) 2025 Евгений Храмов -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -[[translation]] -id = 1228660974 -value = 'Pulling repository' - -[[translation]] -id = 2779805870 -value = 'Repository up to date' - -[[translation]] -id = 1433222829 -value = 'Would you like to view the build script for' - -[[translation]] -id = 2470847050 -value = 'Failed to prompt user to view build script' - -[[translation]] -id = 855659503 -value = 'Would you still like to continue?' - -[[translation]] -id = 1997041569 -value = 'User chose not to continue after reading script' - -[[translation]] -id = 2347700990 -value = 'Building package' - -[[translation]] -id = 2105058868 -value = 'Downloading sources' - -[[translation]] -id = 1884485082 -value = 'Downloading source' - -[[translation]] -id = 1519177982 -value = 'Error building package' - -[[translation]] -id = 2125220917 -value = 'Choose which package(s) to install' - -[[translation]] -id = 812531604 -value = 'Error prompting for choice of package' - -[[translation]] -id = 1040982801 -value = 'Updating version' - -[[translation]] -id = 1014897988 -value = 'Remove build dependencies?' - -[[translation]] -id = 2205430948 -value = 'Installing build dependencies' - -[[translation]] -id = 2522710805 -value = 'Installing dependencies' - -[[translation]] -id = 3602138206 -value = 'Error installing package' - -[[translation]] -id = 2235794125 -value = 'Would you like to remove build dependencies?' - -[[translation]] -id = 2562049386 -value = "Your system's CPU architecture doesn't match this package. Do you want to build anyway?" - -[[translation]] -id = 4006393493 -value = 'The checksums array must be the same length as sources' - -[[translation]] -id = 3759891273 -value = 'The package() function is required' - -[[translation]] -id = 1057080231 -value = 'Executing package()' - -[[translation]] -id = 2687735200 -value = 'Executing prepare()' - -[[translation]] -id = 535572372 -value = 'Executing version()' - -[[translation]] -id = 436644691 -value = 'Executing build()' - -[[translation]] -id = 1393316459 -value = 'This package is already installed' - -[[translation]] -id = 1267660189 -value = 'Source can be updated, updating if required' - -[[translation]] -id = 21753247 -value = 'Source found in cache, linked to destination' - -[[translation]] -id = 257354570 -value = 'Compressing package' - -[[translation]] -id = 2952487371 -value = 'Building package metadata' - -[[translation]] -id = 3121791194 -value = 'Running ALR as root is forbidden as it may cause catastrophic damage to your system' - -[[translation]] -id = 1256604213 -value = 'Waiting for torrent metadata' - -[[translation]] -id = 432261354 -value = 'Downloading torrent file' - -[[translation]] -id = 1579384326 -value = 'name' - -[[translation]] -id = 3206337475 -value = 'version' - -[[translation]] -id = 1810056261 -value = 'new' - -[[translation]] -id = 1602912115 -value = 'source' - -[[translation]] -id = 2363381545 -value = 'type' - -[[translation]] -id = 3419504365 -value = 'downloader' diff --git a/internal/translations/files/lure.ru.toml b/internal/translations/files/lure.ru.toml deleted file mode 100644 index 39d6d41..0000000 --- a/internal/translations/files/lure.ru.toml +++ /dev/null @@ -1,170 +0,0 @@ -# This file was originally part of the project "LURE - Linux User REpository", created by Elara Musayelyan. -# It has been modified as part of "ALR - Any Linux Repository" by Евгений Храмов. -# -# ALR - Any Linux Repository -# Copyright (C) 2025 Евгений Храмов -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -[[translation]] -id = 1228660974 -value = 'Скачивание репозитория' - -[[translation]] -id = 2779805870 -value = 'Репозиторий уже обновлен' - -[[translation]] -id = 1433222829 -value = 'Показать скрипт для пакета' - -[[translation]] -id = 2470847050 -value = 'Не удалось предложить просмотреть скрипт' - -[[translation]] -id = 855659503 -value = 'Продолжить?' - -[[translation]] -id = 1997041569 -value = 'Пользователь решил не продолжать после просмотра скрипта' - -[[translation]] -id = 2347700990 -value = 'Сборка пакета' - -[[translation]] -id = 2105058868 -value = 'Скачивание файлов' - -[[translation]] -id = 1884485082 -value = 'Скачивание источника' - -[[translation]] -id = 1519177982 -value = 'Ошибка при сборке пакета' - -[[translation]] -id = 2125220917 -value = 'Выберите, какие пакеты установить' - -[[translation]] -id = 812531604 -value = 'Ошибка при запросе выбора пакета' - -[[translation]] -id = 1040982801 -value = 'Обновление версии' - -[[translation]] -id = 2235794125 -value = 'Удалить зависимости сборки?' - -[[translation]] -id = 2205430948 -value = 'Установка зависимостей сборки' - -[[translation]] -id = 2522710805 -value = 'Установка зависимостей' - -[[translation]] -id = 3602138206 -value = 'Ошибка при установке пакета' - -[[translation]] -id = 1057080231 -value = 'Вызов функции package()' - -[[translation]] -id = 2687735200 -value = 'Вызов функции prepare()' - -[[translation]] -id = 535572372 -value = 'Вызов функции version()' - -[[translation]] -id = 436644691 -value = 'Вызов функции build()' - -[[translation]] -id = 2562049386 -value = "Архитектура процессора вашей системы не соответствует этому пакету. Продолжать несмотря на это?" - -[[translation]] -id = 3759891273 -value = 'Функция package() необходима' - -[[translation]] -id = 4006393493 -value = 'Массив checksums должен быть той же длины, что и sources' - -[[translation]] -id = 1393316459 -value = 'Этот пакет уже установлен' - -[[translation]] -id = 1267660189 -value = 'Источник может быть обновлен, если требуется, обновляем' - -[[translation]] -id = 21753247 -value = 'Источник найден в кэше' - -[[translation]] -id = 257354570 -value = 'Сжатие пакета' - -[[translation]] -id = 2952487371 -value = 'Создание метаданных пакета' - -[[translation]] -id = 3121791194 -value = 'Запуск ALR от имени root запрещен, так как это может привести к катастрофическому повреждению вашей системы' - -[[translation]] -id = 1256604213 -value = 'Ожидание метаданных торрента' - -[[translation]] -id = 432261354 -value = 'Скачивание торрент-файла' - -[[translation]] -id = 1579384326 -value = 'название' - -[[translation]] -id = 3206337475 -value = 'версия' - -[[translation]] -id = 1810056261 -value = 'новая' - -[[translation]] -id = 1602912115 -value = 'источник' - -[[translation]] -id = 2363381545 -value = 'вид' - -[[translation]] -id = 3419504365 -value = 'протокол-скачивание' \ No newline at end of file diff --git a/internal/translations/po/ru/default.po b/internal/translations/po/ru/default.po index cad7f13..df99b01 100644 --- a/internal/translations/po/ru/default.po +++ b/internal/translations/po/ru/default.po @@ -3,16 +3,16 @@ # msgid "" msgstr "" -"Project-Id-Version: \n" -"PO-Revision-Date: 2025-01-22 14:23+0300\n" +"Project-Id-Version: unnamed project\n" +"PO-Revision-Date: 2025-01-22 16:50+0300\n" "Last-Translator: Maxim Slipenko \n" "Language-Team: Russian\n" "Language: ru\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" -"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Gtranslator 47.1\n" #: build.go:69 @@ -25,7 +25,7 @@ msgstr "" #: build.go:86 msgid "Error building package" -msgstr "" +msgstr "Ошибка при сборке пакета" #: build.go:92 msgid "Error getting working directory" @@ -111,12 +111,28 @@ msgstr "" msgid "Error removing packages" msgstr "" -#: internal/cliutils/prompt.go:80 +#: internal/cliutils/prompt.go:60 +msgid "Would you like to view the build script for %s" +msgstr "Показать скрипт для пакета %s" + +#: internal/cliutils/prompt.go:71 +msgid "Would you still like to continue?" +msgstr "Продолжить?" + +#: internal/cliutils/prompt.go:77 msgid "User chose not to continue after reading script" +msgstr "Пользователь решил не продолжать после просмотра скрипта" + +#: internal/cliutils/prompt.go:111 +msgid "Error prompting for choice of package" msgstr "" -#: internal/cliutils/prompt.go:114 -msgid "Error prompting for choice of package" +#: internal/cliutils/prompt.go:135 +msgid "Choose which package to %s" +msgstr "" + +#: internal/cliutils/prompt.go:156 +msgid "Choose which optional package(s) to install" msgstr "" #: internal/config/config.go:63 @@ -184,14 +200,14 @@ msgstr "" msgid "Source updated and linked to destination" msgstr "" +#: internal/dl/dl.go:222 +msgid "Downloading source" +msgstr "Скачивание источника" + #: internal/logger/log.go:44 msgid "ERROR" msgstr "ОШИБКА" -#: internal/translations/translations.go:52 -msgid "Error creating new translator" -msgstr "" - #: list.go:53 msgid "Error initialization database" msgstr "" @@ -212,15 +228,15 @@ msgstr "" #: pkg/build/build.go:104 msgid "Failed to prompt user to view build script" -msgstr "" +msgstr "Не удалось предложить просмотреть скрипт" #: pkg/build/build.go:108 msgid "Building package" -msgstr "" +msgstr "Сборка пакета" #: pkg/build/build.go:152 msgid "Downloading sources" -msgstr "" +msgstr "Скачивание файлов" #: pkg/build/build.go:164 msgid "Building package metadata" @@ -230,6 +246,12 @@ msgstr "" msgid "Compressing package" msgstr "" +#: pkg/build/build.go:312 +msgid "" +"Your system's CPU architecture doesn't match this package. Do you want to " +"build anyway?" +msgstr "" + #: pkg/build/build.go:323 msgid "This package is already installed" msgstr "" @@ -266,6 +288,10 @@ msgstr "" msgid "AutoReq is not implemented for this package format, so it's skiped" msgstr "" +#: pkg/build/build.go:653 +msgid "Would you like to remove the build dependencies?" +msgstr "" + #: pkg/build/build.go:759 msgid "The checksums array must be the same length as sources" msgstr "" @@ -292,11 +318,11 @@ msgstr "" #: pkg/repos/pull.go:75 msgid "Pulling repository" -msgstr "" +msgstr "Скачивание репозитория" #: pkg/repos/pull.go:99 msgid "Repository up to date" -msgstr "" +msgstr "Репозиторий уже обновлен" #: pkg/repos/pull.go:156 msgid "Git repository does not appear to be a valid ALR repo" diff --git a/internal/translations/translations.go b/internal/translations/translations.go index 42fc2c7..bb541a9 100644 --- a/internal/translations/translations.go +++ b/internal/translations/translations.go @@ -20,47 +20,15 @@ package translations import ( - "context" "embed" "io/fs" - "log/slog" "os" "path" - "sync" "github.com/jeandeaual/go-locale" "github.com/leonelquinteros/gotext" - "go.elara.ws/logger" - "go.elara.ws/translate" - "golang.org/x/text/language" ) -//go:embed files -var translationFS embed.FS - -var ( - mu sync.Mutex - translator *translate.Translator -) - -func Translator(ctx context.Context) *translate.Translator { - mu.Lock() - defer mu.Unlock() - if translator == nil { - t, err := translate.NewFromFS(translationFS) - if err != nil { - slog.Error(gotext.Get("Error creating new translator"), "err", err) - os.Exit(1) - } - translator = &t - } - return translator -} - -func NewLogger(ctx context.Context, l logger.Logger, lang language.Tag) *translate.TranslatedLogger { - return translate.NewLogger(l, *Translator(ctx), lang) -} - //go:embed po var poFS embed.FS diff --git a/pkg/build/build.go b/pkg/build/build.go index 249529a..293fdca 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -309,7 +309,7 @@ func prepareDirs(dirs types.Directories) error { // Функция performChecks проверяет различные аспекты в системе, чтобы убедиться, что пакет может быть установлен. func performChecks(ctx context.Context, vars *types.BuildVars, interactive bool, installed map[string]string) (bool, error) { if !cpu.IsCompatibleWith(cpu.Arch(), vars.Architectures) { // Проверяем совместимость архитектуры - cont, err := cliutils.YesNoPrompt(ctx, "Your system's CPU architecture doesn't match this package. Do you want to build anyway?", interactive, true) + cont, err := cliutils.YesNoPrompt(ctx, gotext.Get("Your system's CPU architecture doesn't match this package. Do you want to build anyway?"), interactive, true) if err != nil { return false, err } @@ -650,7 +650,7 @@ func buildContents(vars *types.BuildVars, dirs types.Directories) ([]*files.Cont // установленные для сборки. Если да, использует менеджер пакетов для их удаления. func removeBuildDeps(ctx context.Context, buildDeps []string, opts types.BuildOpts) error { if len(buildDeps) > 0 { - remove, err := cliutils.YesNoPrompt(ctx, "Would you like to remove the build dependencies?", opts.Interactive, false) + remove, err := cliutils.YesNoPrompt(ctx, gotext.Get("Would you like to remove the build dependencies?"), opts.Interactive, false) if err != nil { return err }