i18n.mx raw

   1  package main
   2  
   3  import (
   4  	"smesh.lol/web/common/jsbridge/localstorage"
   5  )
   6  
   7  const lsKeyLang = "smesh-lang"
   8  
   9  var currentLang = "en"
  10  
  11  // t returns the translated string for the given key in the current language.
  12  func t(key string) string {
  13  	if m, ok := translations[currentLang]; ok {
  14  		if s, ok := m[key]; ok {
  15  			return s
  16  		}
  17  	}
  18  	// Fallback to English.
  19  	if s, ok := translations["en"][key]; ok {
  20  		return s
  21  	}
  22  	return key
  23  }
  24  
  25  func setLang(lang string) {
  26  	if _, ok := translations[lang]; !ok {
  27  		return
  28  	}
  29  	currentLang = lang
  30  	localstorage.SetItem(lsKeyLang, lang)
  31  }
  32  
  33  func initLang() {
  34  	saved := localstorage.GetItem(lsKeyLang)
  35  	if saved != "" {
  36  		if _, ok := translations[saved]; ok {
  37  			currentLang = saved
  38  			return
  39  		}
  40  	}
  41  }
  42  
  43  // countryToLang maps country codes to language codes.
  44  func countryToLang(cc string) string {
  45  	switch cc {
  46  	case "JP":
  47  		return "ja"
  48  	case "BR", "PT", "AO", "MZ", "CV", "GW", "ST", "TL":
  49  		return "pt"
  50  	}
  51  	return "en"
  52  }
  53  
  54  var langNames = map[string]string{
  55  	"en": "English",
  56  	"ja": "日本語",
  57  	"pt": "Português",
  58  }
  59  
  60  var translations = map[string]map[string]string{
  61  	"en": {
  62  		// Login page.
  63  		"subtitle":        "Sovereign Messaging, Encryption, Sync & Heuristics",
  64  		"login":           "login with extension",
  65  		"requesting":      "requesting...",
  66  		"install_signer":  "install signer extension",
  67  		"err_no_ext":      "extension not detected — install it first",
  68  		"err_no_id":       "no identity — open signer to add one",
  69  		"req_fennec":      "S.M.E.S.H. requires Fennec (Firefox) with the signer extension.",
  70  		"req_librewolf":   "S.M.E.S.H. requires LibreWolf (or Firefox) with the signer extension.",
  71  		"get_fennec":      "Get Fennec on F-Droid",
  72  		"dl_librewolf":    "Download LibreWolf",
  73  		"chrome_why":      "Chrome and Chrome based browsers force the use of complex and slow tooling and disrupts the parallel processing architecture of this app.",
  74  		"language":        "Language",
  75  		"theme":           "Theme",
  76  		"dark":            "dark",
  77  		"light":           "light",
  78  
  79  		// Top bar / nav.
  80  		"back":        "\u2190 back",
  81  		"feed":        "feed",
  82  		"messaging":   "messaging",
  83  		"settings":    "settings",
  84  
  85  		// Feed.
  86  		"connecting":  "connecting...",
  87  		"show_more":   "show more",
  88  		"show_less":   "show less",
  89  
  90  		// Thread view.
  91  		"loading_thread": "loading thread...",
  92  		"thread_empty":   "thread not found",
  93  		"replying_to":    "replying to...",
  94  
  95  		// Profile.
  96  		"notes":      "notes",
  97  		"follows":    "follows",
  98  		"relays":     "relays",
  99  		"mutes":      "mutes",
 100  		"no_follows": "no follows data",
 101  		"no_relays":  "no relay data",
 102  		"no_mutes":   "no mutes data",
 103  		"following":  "following",
 104  		"muted":      "muted",
 105  		"copy":       "copy",
 106  		"qr":         "qr",
 107  		"message":    "message",
 108  		"loading":    "loading...",
 109  		"relay_info": "relay info",
 110  		"relay_fail": "failed to fetch relay info",
 111  
 112  		// Messaging.
 113  		"new_chat":       "+ new chat",
 114  		"no_convos":      "no conversations yet",
 115  		"npub_placeholder": "npub or hex pubkey",
 116  		"go":             "go",
 117  		"msg_placeholder": "message...",
 118  		"send":           "send",
 119  		"dm_notice":      "encrypted DMs require the <b>Smesh Signer</b> extension",
 120  		"ratchet":        "ratchet",
 121  
 122  		// About.
 123  		"developed_by":   "developed by:",
 124  		"tagline":        "Can Youse Paradigm?",
 125  		"about_donkey":   "Every hour you don't zap, a donkey eats another cabbage. You can stop this. \U0001FABE",
 126  
 127  		// Settings.
 128  		"settings_title": "Settings",
 129  		"lang_label":     "Interface language",
 130  		"theme_label":    "Appearance",
 131  
 132  		// Signer.
 133  		"signer":               "Signer",
 134  		"no_vault":             "No vault found. Create a new one.",
 135  		"hd_keychain":          "HD Keychain",
 136  		"vault_password":       "Vault password",
 137  		"generate_keychain":    "Generate New Keychain",
 138  		"generating":           "Generating keychain...",
 139  		"create_failed":        "Failed to create vault.",
 140  		"restore_seed":         "Restore from Seed Phrase",
 141  		"seed_placeholder":     "12-word seed phrase",
 142  		"account_placeholder":  "Account number (default: 1)",
 143  		"restore_keychain":     "Restore Keychain",
 144  		"restoring":            "Restoring keychain...",
 145  		"restore_failed":       "Invalid seed phrase or vault creation failed.",
 146  		"deriving_n":           "Deriving identity",
 147  		"import_vault":         "Import Vault File",
 148  		"choose_vault":         "Choose Vault File...",
 149  		"vault_imported":       "Vault imported. Unlock with your password.",
 150  		"invalid_vault":        "Invalid vault file.",
 151  		"write_seed":           "Write Down Your Seed Phrase",
 152  		"seed_warning":         "This is the ONLY way to recover your identities. Write these words down and store them safely. They will not be shown again.",
 153  		"copy_clipboard":       "Copy to Clipboard",
 154  		"copied":               "Copied!",
 155  		"saved_it":             "I've Saved It",
 156  		"vault_locked":         "Vault is locked.",
 157  		"password":             "Password",
 158  		"unlock":               "Unlock",
 159  		"deriving_key":         "Deriving key, this may take a minute...",
 160  		"wrong_password":       "Wrong password.",
 161  		"identities":           "Identities",
 162  		"nickname_placeholder": "Nickname for new identity",
 163  		"derive_new":           "Derive New Identity",
 164  		"deriving":             "Deriving...",
 165  		"show_seed":            "Show Seed Phrase",
 166  		"export_vault":         "Export Vault",
 167  		"lock_vault":           "Lock Vault",
 168  		"reset_extension":      "Reset Extension",
 169  		"reset_confirm":        "This will erase all keys. Are you sure?",
 170  		"use":                  "Use",
 171  		"publish":              "Publish",
 172  		"add":                  "Add",
 173  	},
 174  	"ja": {
 175  		"subtitle":        "主権あるメッセージング、暗号化、同期 & ヒューリスティクス",
 176  		"login":           "拡張機能でログイン",
 177  		"requesting":      "リクエスト中...",
 178  		"install_signer":  "署名拡張機能をインストール",
 179  		"err_no_ext":      "拡張機能が検出されません — まずインストールしてください",
 180  		"err_no_id":       "IDがありません — 署名拡張を開いて追加してください",
 181  		"req_fennec":      "S.M.E.S.H.にはFennec(Firefox)と署名拡張が必要です。",
 182  		"req_librewolf":   "S.M.E.S.H.にはLibreWolf(またはFirefox)と署名拡張が必要です。",
 183  		"get_fennec":      "F-DroidでFennecを入手",
 184  		"dl_librewolf":    "LibreWolfをダウンロード",
 185  		"chrome_why":      "ChromeやChromiumベースのブラウザは複雑で遅いツールを強制し、このアプリの並列処理アーキテクチャを妨害します。",
 186  		"language":        "言語",
 187  		"theme":           "テーマ",
 188  		"dark":            "ダーク",
 189  		"light":           "ライト",
 190  
 191  		"back":        "\u2190 戻る",
 192  		"feed":        "フィード",
 193  		"messaging":   "メッセージ",
 194  		"settings":    "設定",
 195  
 196  		"connecting":  "接続中...",
 197  		"show_more":   "もっと見る",
 198  		"show_less":   "閉じる",
 199  
 200  		"loading_thread": "スレッド読み込み中...",
 201  		"thread_empty":   "スレッドが見つかりません",
 202  		"replying_to":    "返信先...",
 203  
 204  		"notes":      "ノート",
 205  		"follows":    "フォロー",
 206  		"relays":     "リレー",
 207  		"mutes":      "ミュート",
 208  		"no_follows": "フォローデータなし",
 209  		"no_relays":  "リレーデータなし",
 210  		"no_mutes":   "ミュートデータなし",
 211  		"following":  "フォロー中",
 212  		"muted":      "ミュート中",
 213  		"copy":       "コピー",
 214  		"qr":         "QR",
 215  		"message":    "メッセージ",
 216  		"loading":    "読み込み中...",
 217  		"relay_info": "リレー情報",
 218  		"relay_fail": "リレー情報の取得に失敗しました",
 219  
 220  		"new_chat":       "+ 新しいチャット",
 221  		"no_convos":      "会話がまだありません",
 222  		"npub_placeholder": "npubまたは16進公開鍵",
 223  		"go":             "実行",
 224  		"msg_placeholder": "メッセージ...",
 225  		"send":           "送信",
 226  		"dm_notice":      "暗号化DMには<b>Smesh Signer</b>拡張が必要です",
 227  		"ratchet":        "ラチェット",
 228  
 229  		"developed_by":   "開発者:",
 230  		"tagline":        "Can Youse Paradigm?",
 231  		"about_donkey":   "zapしないと毎時間ロバがキャベツを食べてしまいます。止められるのはあなたです。\U0001FABE",
 232  
 233  		"settings_title": "設定",
 234  		"lang_label":     "表示言語",
 235  		"theme_label":    "外観",
 236  
 237  		"signer":               "署名",
 238  		"no_vault":             "金庫が見つかりません。新規作成してください。",
 239  		"hd_keychain":          "HDキーチェーン",
 240  		"vault_password":       "金庫のパスワード",
 241  		"generate_keychain":    "新しいキーチェーンを生成",
 242  		"generating":           "キーチェーン生成中...",
 243  		"create_failed":        "金庫の作成に失敗しました。",
 244  		"restore_seed":         "シードフレーズから復元",
 245  		"seed_placeholder":     "12語のシードフレーズ",
 246  		"account_placeholder":  "アカウント番号(デフォルト: 1)",
 247  		"restore_keychain":     "キーチェーンを復元",
 248  		"restoring":            "キーチェーン復元中...",
 249  		"restore_failed":       "シードフレーズが無効か、金庫の作成に失敗しました。",
 250  		"deriving_n":           "ID導出中",
 251  		"import_vault":         "金庫ファイルをインポート",
 252  		"choose_vault":         "金庫ファイルを選択...",
 253  		"vault_imported":       "金庫をインポートしました。パスワードでロック解除してください。",
 254  		"invalid_vault":        "無効な金庫ファイルです。",
 255  		"write_seed":           "シードフレーズを書き留めてください",
 256  		"seed_warning":         "これがIDを復元する唯一の方法です。これらの単語を書き留めて安全に保管してください。再表示されません。",
 257  		"copy_clipboard":       "クリップボードにコピー",
 258  		"copied":               "コピー済み!",
 259  		"saved_it":             "保存しました",
 260  		"vault_locked":         "金庫はロックされています。",
 261  		"password":             "パスワード",
 262  		"unlock":               "ロック解除",
 263  		"deriving_key":         "鍵を導出中です。しばらくお待ちください...",
 264  		"wrong_password":       "パスワードが違います。",
 265  		"identities":           "ID一覧",
 266  		"nickname_placeholder": "新しいIDのニックネーム",
 267  		"derive_new":           "新しいIDを導出",
 268  		"deriving":             "導出中...",
 269  		"show_seed":            "シードフレーズを表示",
 270  		"export_vault":         "金庫をエクスポート",
 271  		"lock_vault":           "金庫をロック",
 272  		"reset_extension":      "拡張機能をリセット",
 273  		"reset_confirm":        "すべての鍵が削除されます。よろしいですか?",
 274  		"use":                  "使用",
 275  		"publish":              "公開",
 276  		"add":                  "追加",
 277  	},
 278  	"pt": {
 279  		"subtitle":        "Mensagens Soberanas, Encriptação, Sincronização & Heurísticas",
 280  		"login":           "entrar com extensão",
 281  		"requesting":      "solicitando...",
 282  		"install_signer":  "instalar extensão de assinatura",
 283  		"err_no_ext":      "extensão não detectada — instale primeiro",
 284  		"err_no_id":       "sem identidade — abra o signer para adicionar uma",
 285  		"req_fennec":      "S.M.E.S.H. requer Fennec (Firefox) com a extensão de assinatura.",
 286  		"req_librewolf":   "S.M.E.S.H. requer LibreWolf (ou Firefox) com a extensão de assinatura.",
 287  		"get_fennec":      "Obter Fennec no F-Droid",
 288  		"dl_librewolf":    "Baixar LibreWolf",
 289  		"chrome_why":      "Navegadores baseados no Chrome forçam o uso de ferramentas complexas e lentas e interrompem a arquitetura de processamento paralelo deste aplicativo.",
 290  		"language":        "Idioma",
 291  		"theme":           "Tema",
 292  		"dark":            "escuro",
 293  		"light":           "claro",
 294  
 295  		"back":        "\u2190 voltar",
 296  		"feed":        "feed",
 297  		"messaging":   "mensagens",
 298  		"settings":    "configurações",
 299  
 300  		"connecting":  "conectando...",
 301  		"show_more":   "mostrar mais",
 302  		"show_less":   "mostrar menos",
 303  
 304  		"loading_thread": "carregando thread...",
 305  		"thread_empty":   "thread não encontrada",
 306  		"replying_to":    "respondendo a...",
 307  
 308  		"notes":      "notas",
 309  		"follows":    "seguindo",
 310  		"relays":     "relays",
 311  		"mutes":      "silenciados",
 312  		"no_follows": "sem dados de seguidos",
 313  		"no_relays":  "sem dados de relays",
 314  		"no_mutes":   "sem dados de silenciados",
 315  		"following":  "seguindo",
 316  		"muted":      "silenciados",
 317  		"copy":       "copiar",
 318  		"qr":         "qr",
 319  		"message":    "mensagem",
 320  		"loading":    "carregando...",
 321  		"relay_info": "info do relay",
 322  		"relay_fail": "falha ao buscar info do relay",
 323  
 324  		"new_chat":       "+ novo chat",
 325  		"no_convos":      "nenhuma conversa ainda",
 326  		"npub_placeholder": "npub ou chave pública hex",
 327  		"go":             "ir",
 328  		"msg_placeholder": "mensagem...",
 329  		"send":           "enviar",
 330  		"dm_notice":      "DMs encriptadas requerem a extensão <b>Smesh Signer</b>",
 331  		"ratchet":        "ratchet",
 332  
 333  		"developed_by":   "desenvolvido por:",
 334  		"tagline":        "Can Youse Paradigm?",
 335  		"about_donkey":   "A cada hora que você não dá zap, um burro come outro repolho. Você pode impedir isso. \U0001FABE",
 336  
 337  		"settings_title": "Configurações",
 338  		"lang_label":     "Idioma da interface",
 339  		"theme_label":    "Aparência",
 340  
 341  		"signer":               "Assinador",
 342  		"no_vault":             "Nenhum cofre encontrado. Crie um novo.",
 343  		"hd_keychain":          "Chaveiro HD",
 344  		"vault_password":       "Senha do cofre",
 345  		"generate_keychain":    "Gerar Novo Chaveiro",
 346  		"generating":           "Gerando chaveiro...",
 347  		"create_failed":        "Falha ao criar cofre.",
 348  		"restore_seed":         "Restaurar com Frase Semente",
 349  		"seed_placeholder":     "Frase semente de 12 palavras",
 350  		"account_placeholder":  "Número da conta (padrão: 1)",
 351  		"restore_keychain":     "Restaurar Chaveiro",
 352  		"restoring":            "Restaurando chaveiro...",
 353  		"restore_failed":       "Frase semente inválida ou falha ao criar cofre.",
 354  		"deriving_n":           "Derivando identidade",
 355  		"import_vault":         "Importar Arquivo de Cofre",
 356  		"choose_vault":         "Escolher Arquivo de Cofre...",
 357  		"vault_imported":       "Cofre importado. Desbloqueie com sua senha.",
 358  		"invalid_vault":        "Arquivo de cofre inválido.",
 359  		"write_seed":           "Anote Sua Frase Semente",
 360  		"seed_warning":         "Esta é a ÚNICA forma de recuperar suas identidades. Anote estas palavras e guarde-as em segurança. Elas não serão exibidas novamente.",
 361  		"copy_clipboard":       "Copiar para Área de Transferência",
 362  		"copied":               "Copiado!",
 363  		"saved_it":             "Já Salvei",
 364  		"vault_locked":         "Cofre está bloqueado.",
 365  		"password":             "Senha",
 366  		"unlock":               "Desbloquear",
 367  		"deriving_key":         "Derivando chave, isso pode levar um minuto...",
 368  		"wrong_password":       "Senha incorreta.",
 369  		"identities":           "Identidades",
 370  		"nickname_placeholder": "Apelido para nova identidade",
 371  		"derive_new":           "Derivar Nova Identidade",
 372  		"deriving":             "Derivando...",
 373  		"show_seed":            "Mostrar Frase Semente",
 374  		"export_vault":         "Exportar Cofre",
 375  		"lock_vault":           "Bloquear Cofre",
 376  		"reset_extension":      "Redefinir Extensão",
 377  		"reset_confirm":        "Isso apagará todas as chaves. Tem certeza?",
 378  		"use":                  "Usar",
 379  		"publish":              "Publicar",
 380  		"add":                  "Adicionar",
 381  	},
 382  }
 383