Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/app/service/script_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ func (u *ScriptService) Sync(req dto.OperateByTaskID) error {
if global.CONF.Base.IsOffLine {
return nil
}
syncTask, err := task.NewTaskWithOps(i18n.GetMsgByKey("ScriptLibrary"), task.TaskSync, task.TaskScopeScript, req.TaskID, 0)
syncTask, err := task.NewTaskWithOps(i18n.GetMsgByKey("RemoteScriptLibrary"), task.TaskSync, task.TaskScopeScript, req.TaskID, 0)
if err != nil {
global.LOG.Errorf("create sync task failed %v", err)
return err
}

syncTask.AddSubTask(task.GetTaskName(i18n.GetMsgByKey("ScriptLibrary"), task.TaskSync, task.TaskScopeScript), func(t *task.Task) (err error) {
syncTask.AddSubTask(task.GetTaskName(i18n.GetMsgByKey("RemoteScriptLibrary"), task.TaskSync, task.TaskScopeScript), func(t *task.Task) (err error) {
versionUrl := fmt.Sprintf("%s/scripts/version.txt", global.CONF.RemoteURL.ResourceURL)
_, versionRes, err := req_helper.HandleRequestWithProxy(versionUrl, http.MethodGet, constant.TimeOut20s)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/app/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
TaskUpgrade = "TaskUpgrade"
TaskAddNode = "TaskAddNode"
TaskSync = "TaskSync"
TaskSyncForNode = "TaskSyncForNode"
TaskRsync = "TaskRsync"
TaskInstallCluster = "TaskInstallCluster"
TaskCreateCluster = "TaskCreateCluster"
Expand Down
75 changes: 46 additions & 29 deletions core/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package i18n
import (
"embed"
"fmt"
"os/exec"
"strings"
"sync"
"sync/atomic"

"github.com/1Panel-dev/1Panel/core/app/repo"

"github.com/1Panel-dev/1Panel/core/global"

"github.com/gin-gonic/gin"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
Expand Down Expand Up @@ -140,38 +138,29 @@ func UseI18n() gin.HandlerFunc {
}

func Init() {
initOnce.Do(func() {
bundle = i18n.NewBundle(language.Chinese)
bundle.RegisterUnmarshalFunc("yaml", yaml.Unmarshal)

isSuccess := true
for _, file := range langFiles {
if _, err := bundle.LoadMessageFileFS(fs, file); err != nil {
fmt.Printf("[i18n] load language file %s failed: %v\n", file, err)
isSuccess = false
}
}

if !isSuccess {
panic("[i18n] failed to init language files, See log above for details")
}

dbLang := getLanguageFromDBInternal()
if dbLang == "" {
dbLang = defaultLang
}
SetCachedDBLanguage(dbLang)
if bundle == nil {
initBundle()
}
dbLang := getLanguageFromDBInternal()
if dbLang == "" {
dbLang = defaultLang
}
SetCachedDBLanguage(dbLang)

global.I18n = i18n.NewLocalizer(bundle, dbLang)
})
global.I18n = i18n.NewLocalizer(bundle, dbLang)
}

func UseI18nForCmd(lang string) {
if bundle == nil {
Init()
initBundle()
}
if lang == "" {
lang = defaultLang
langFrom1pctl := getLanguageFrom1pctl()
if langFrom1pctl == "" {
lang = defaultLang
} else {
lang = langFrom1pctl
}
}
global.I18nForCmd = i18n.NewLocalizer(bundle, lang)
}
Expand Down Expand Up @@ -219,9 +208,20 @@ func getLanguageFromDBInternal() string {
}
return lang
}
func getLanguageFrom1pctl() string {
cmd := exec.Command("bash", "-c", "grep '^LANGUAGE=' /usr/local/bin/1pctl | cut -d'=' -f2")
stdout, err := cmd.CombinedOutput()
if err != nil {
panic(err)
}
info := strings.ReplaceAll(string(stdout), "\n", "")
if len(info) == 0 || info == `""` {
panic("error `LANGUAGE` find in /usr/local/bin/1pctl")
}
return info
}

var cachedDBLang atomic.Value
var initOnce sync.Once

func GetLanguage() string {
if v := cachedDBLang.Load(); v != nil {
Expand All @@ -236,3 +236,20 @@ func SetCachedDBLanguage(lang string) {
}
cachedDBLang.Store(lang)
}

func initBundle() {
bundle = i18n.NewBundle(language.Chinese)
bundle.RegisterUnmarshalFunc("yaml", yaml.Unmarshal)

isSuccess := true
for _, file := range langFiles {
if _, err := bundle.LoadMessageFileFS(fs, file); err != nil {
fmt.Printf("[i18n] load language file %s failed: %v\n", file, err)
isSuccess = false
}
}

if !isSuccess {
panic("[i18n] failed to init language files, See log above for details")
}
}
2 changes: 2 additions & 0 deletions core/i18n/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} failed: {{ .err }}"
TaskInstall: "Install"
TaskUpgrade: "Upgrade"
TaskSync: 'Synchronize'
TaskSyncForNode: "Sync Node Data"
TaskBackup: "Backup"
SuccessStatus: "{{ .name }} succeeded"
FailedStatus: "{{ .name }} failed {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "Skip errors and continue..."

#script
ScriptLibrary: "Script Library"
RemoteScriptLibrary: "Remote Script Library"
ScriptSyncSkip: "Current script library is already the latest version!"
DownloadData: "Downloading script library file data.yaml"
DownloadPackage: "Downloading script library package"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} falló: {{ .err }}"
TaskInstall: "Instalar"
TaskUpgrade: "Actualizar"
TaskSync: 'Sincronizar'
TaskSyncForNode: "Sincronizar Datos del Nodo"
TaskBackup: "Respaldar"
SuccessStatus: "{{ .name }} correcta"
FailedStatus: "{{ .name }} fallida {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "Omitir errores y continuar..."

#script
ScriptLibrary: "Biblioteca de scripts"
RemoteScriptLibrary: "Biblioteca de Scripts Remota"
ScriptSyncSkip: "¡La biblioteca de scripts ya está en la última versión!"
DownloadData: "Descargando archivo de datos de la biblioteca de scripts data.yaml"
DownloadPackage: "Descargando paquete de la biblioteca de scripts"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ SubTaskFailed: "{{ .name }} 失敗: {{ .err }}"
TaskInstall: "インストール"
TaskUpgrade: "アップグレード"
TaskSync: '同期'
TaskSyncForNode: "ノードデータを同期"
TaskBackup: "バックアップ"
SuccessStatus: "{{ .name }} 成功"
FailedStatus: "{{ .name }} 失敗 {{ .err }}"
Expand All @@ -113,6 +114,7 @@ Skip: "エラーを無視して続行..."

#script
ScriptLibrary: "スクリプトライブラリ"
RemoteScriptLibrary: "リモートスクリプトライブラリ"
ScriptSyncSkip: "現在のスクリプトライブラリは最新バージョンです!"
DownloadData: "スクリプトライブラリファイル data.yaml をダウンロード中"
DownloadPackage: "スクリプトライブラリパッケージをダウンロード中"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} 실패: {{ .err }}"
TaskInstall: "설치"
TaskUpgrade: "업그레이드"
TaskSync: '동기화'
TaskSyncForNode: "노드 데이터 동기화"
TaskBackup: "백업"
SuccessStatus: "{{ .name }} 성공"
FailedStatus: "{{ .name }} 실패 {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "오류 무시하고 계속..."

#script
ScriptLibrary: "스크립트 라이브러리"
RemoteScriptLibrary: "원격 스크립트 라이브러리"
ScriptSyncSkip: "현재 스크립트 라이브러리가 이미 최신 버전입니다!"
DownloadData: "스크립트 라이브러리 파일 data.yaml 다운로드 중"
DownloadPackage: "스크립트 라이브러리 패키지 다운로드 중"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/ms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ SubTaskFailed: "{{ .name }} gagal: {{ .err }}"
TaskInstall: "Pasang"
TaskUpgrade: "Kemas kini"
TaskSync: 'Selaraskan'
TaskSyncForNode: "Segerakan Data Nod"
TaskBackup: "Sandaran"
SuccessStatus: "{{ .name }} berjaya"
FailedStatus: "{{ .name }} gagal {{ .err }}"
Expand All @@ -107,6 +108,7 @@ Skip: "Abaikan ralat dan teruskan..."

#script
ScriptLibrary: "Pustaka Skrip"
RemoteScriptLibrary: "Pustaka Skrip Jauh"
ScriptSyncSkip: "Pustaka skrip semasa sudah versi terkini!"
DownloadData: "Muat turun fail pustaka skrip data.yaml"
DownloadPackage: "Muat turun pakej pustaka skrip"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/pt-BR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} falhou: {{ .err }}"
TaskInstall: "Instalar"
TaskUpgrade: "Atualizar"
TaskSync: 'Sincronizar'
TaskSyncForNode: "Sincronizar Dados do Nó"
TaskBackup: "Backup"
SuccessStatus: "{{ .name }} bem-sucedido"
FailedStatus: "{{ .name }} falhou {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "Ignorar erros e continuar..."

#script
ScriptLibrary: "Biblioteca de Scripts"
RemoteScriptLibrary: "Biblioteca de Scripts Remota"
ScriptSyncSkip: "A biblioteca de scripts atual já é a versão mais recente!"
DownloadData: "Baixando arquivo data.yaml da biblioteca de scripts"
DownloadPackage: "Baixando pacote da biblioteca de scripts"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} не удалось: {{ .err }}"
TaskInstall: "Установить"
TaskUpgrade: "Обновить"
TaskSync: 'Синхронизация'
TaskSyncForNode: "Синхронизировать Данные Узла"
TaskBackup: "Резервная копия"
SuccessStatus: "{{ .name }} успешно"
FailedStatus: "{{ .name }} не удалось {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "Пропустить ошибки и продолжить..."

#script
ScriptLibrary: "Библиотека скриптов"
RemoteScriptLibrary: "Удаленная Библиотека Скриптов"
ScriptSyncSkip: "Текущая библиотека скриптов уже является последней версией!"
DownloadData: "Загрузка файла библиотеки скриптов data.yaml"
DownloadPackage: "Загрузка архива библиотеки скриптов"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/tr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ SubTaskFailed: "{{ .name }} başarısız: {{ .err }}"
TaskInstall: "Kurulum"
TaskUpgrade: "Yükseltme"
TaskSync: 'Senkronize'
TaskSyncForNode: "Düğüm Verilerini Senkronize Et"
TaskBackup: "Yedekleme"
SuccessStatus: "{{ .name }} başarılı"
FailedStatus: "{{ .name }} başarısız {{ .err }}"
Expand All @@ -111,6 +112,7 @@ Skip: "Hataları atla ve devam et..."

#script
ScriptLibrary: "Betik Kütüphanesi"
RemoteScriptLibrary: "Uzak Komut Dosyası Kütüphanesi"
ScriptSyncSkip: "Mevcut betik kütüphanesi zaten en son sürüm!"
DownloadData: "Betik kütüphanesi dosyası data.yaml indiriliyor"
DownloadPackage: "Betik kütüphanesi paketi indiriliyor"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} 失敗: {{ .err }}"
TaskInstall: "安裝"
TaskUpgrade: "升級"
TaskSync: "同步"
TaskSyncForNode: "同步節點數據"
TaskBackup: "備份"
SuccessStatus: "{{ .name }} 成功"
FailedStatus: "{{ .name }} 失敗 {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "忽略錯誤並繼續..."

#script
ScriptLibrary: "腳本庫"
RemoteScriptLibrary: "遠端腳本庫"
ScriptSyncSkip: "目前腳本庫已是最新版本!"
DownloadData: "下載腳本庫文件 data.yaml"
DownloadPackage: "下載腳本庫壓縮檔"
Expand Down
2 changes: 2 additions & 0 deletions core/i18n/lang/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SubTaskFailed: "{{ .name }} 失败: {{ .err }}"
TaskInstall: "安装"
TaskUpgrade: "升级"
TaskSync: "同步"
TaskSyncForNode: "同步节点数据"
TaskBackup: "备份"
SuccessStatus: "{{ .name }} 成功"
FailedStatus: "{{ .name }} 失败 {{ .err }}"
Expand All @@ -112,6 +113,7 @@ Skip: "忽略错误并继续..."

#script
ScriptLibrary: "脚本库"
RemoteScriptLibrary: "远程脚本库"
ScriptSyncSkip: "检查到当前脚本库已是最新版本!"
DownloadData: "下载脚本库文件 data.yaml"
DownloadPackage: "下载脚本库压缩包"
Expand Down
Loading