lang.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. )
  6. func getlist (lang string) []byte {
  7. var jloc = []byte(`{
  8. "top": "トップ",
  9. "fuseiurl": "不正なURL",
  10. "tansyukuzumi": "短縮済み",
  11. "mikensyutu": "未検出",
  12. "errfusei": "URLは「http://」又は「https://」で始めます。",
  13. "errcharlim": "URLは500文字以内です。",
  14. "errurlent": "URLをご入力下さい。",
  15. "errurlnai": "このURLを見つけられませんでした。"
  16. }`)
  17. var eloc = []byte(`{
  18. "top": "Top",
  19. "fuseiurl": "Invalid URL",
  20. "tansyukuzumi": "Shortened",
  21. "mikensyutu": "Not found",
  22. "errfusei": "The URL should start with \"http://\" or \"https://\".",
  23. "errcharlim": "The URL should be less than 500 characters.",
  24. "errurlent": "Please enter a URL.",
  25. "errurlnai": "This URL could not be found."
  26. }`)
  27. if lang == "en" { return eloc }
  28. return jloc
  29. }
  30. func getloc (str string, lang string) string {
  31. var payload map[string]interface{}
  32. err := json.Unmarshal(getlist(lang), &payload)
  33. if err != nil {
  34. fmt.Println("loc:", err)
  35. return ""
  36. }
  37. for k, v := range payload {
  38. if str == k {
  39. return v.(string)
  40. }
  41. }
  42. return ""
  43. }