package locale

import "github.com/O6lvl4/gformiac/locale"

Package locale provides internationalization support for gformiac. It auto-detects the display language from environment variables and allows runtime switching between supported languages via Set.

Index

Variables

var En = Messages{

	CmdLong:     "Declaratively manage Google Forms from YAML definitions",
	PlanShort:   "Preview changes (dry-run)",
	ApplyShort:  "Apply form definition",
	ImportShort: "Import an existing Google Form to YAML",

	FlagFile:        "Form definition file",
	FlagCredentials: "OAuth2 credentials file",
	FlagToken:       "OAuth token file",
	FlagState:       "State file",
	FlagAutoApprove: "Skip confirmation prompt",
	FlagOutput:      "Output file (defaults to --file value)",
	FlagLang:        "Language (en, ja)",

	NoChanges:     "No changes",
	NoChangesLong: "No changes — form is up to date",
	FormInfo:      "Form info:",
	DiffSummary:   "Total: +%d ~%d -%d",

	NewFormHeader: "Creating new form:",
	CreateSummary: "Total: %d items to create",

	Creating:     "Creating form...",
	Applied:      "Applied!",
	Cancelled:    "Cancelled",
	ConfirmApply: "Apply?",
	FormIDLabel:  "  Form ID:    %s",
	URLLabel:     "  URL:        %s",
	StateLabel:   "  State file: %s",

	Imported:      "Import completed!",
	SpecFileLabel: "  Spec file:  %s",
	ItemCount:     "  Items:      %d",

	AuthBrowser:     "Authenticating via browser...",
	AuthSuccessHTML: "<h2>Authentication successful!</h2><p>You can close this tab and return to the terminal.</p>",
	AuthFailedHTML:  "<h2>Authentication failed</h2><p>Auth code was not received.</p>",
	AuthCodeMissing: "auth code not found in callback",
	AuthTimeout:     "authentication timeout (2 min)",
	AuthOpenURL:     "Open this URL in your browser:\n%s",

	ValErrors:      "Validation errors (%d):\n  %s",
	ValTitle:       "title is required",
	ValItems:       "items must have at least one entry",
	ValItemTitle:   "%s: title is required",
	ValItemType:    "%s: type is required",
	ValTypeUnknown: "%s: unknown type %q (valid: %s)",
	ValChoiceReq:   "%s: choice field is required for type=choice",
	ValChoiceType:  "%s: unknown choice.type %q (valid: %s)",
	ValChoiceOpts:  "%s: choice.options requires at least one entry",
	ValChoiceEmpty: "%s: choice.options[%d] must not be empty",
	ValScaleReq:    "%s: scale field is required for type=scale",
	ValScaleLow:    "%s: scale.low must be 0 or 1 (got %d)",
	ValScaleHigh:   "%s: scale.high must be 2-10 (got %d)",
	ValScaleRange:  "%s: scale.low (%d) must be less than scale.high (%d)",

	ErrReadFile:    "reading file",
	ErrParseYAML:   "parsing YAML",
	ErrTitleReq:    "title is required",
	ErrCredentials: "reading credentials",
	ErrCredsParse:  "parsing credentials",
	ErrAuth:        "authentication failed",
	ErrTokenSave:   "saving token",
	ErrFormsInit:   "initializing Forms API",
	ErrFormCreate:  "creating form",
	ErrFormSetup:   "configuring form",
	ErrFormGet:     "fetching form",
	ErrFormUpdate:  "updating form",
	ErrLocalServer: "starting local server",
	ErrStateSave:   "saving state",
	ErrStateRead:   "reading state",
	ErrSpecSave:    "saving spec",
	ErrCredsHint:   "\n\nHint: run `gcloud auth application-default login --scopes=%s,https://www.googleapis.com/auth/cloud-platform` or place an OAuth2 credentials.json file",
}

En is the English message catalog.

var Ja = Messages{

	CmdLong:     "YAML定義からGoogle Formsを宣言的に管理するIaCツール",
	PlanShort:   "変更のプレビュー(dry-run)",
	ApplyShort:  "フォーム定義を適用",
	ImportShort: "既存のGoogle FormをYAML定義にインポート",

	FlagFile:        "フォーム定義ファイル",
	FlagCredentials: "OAuth2認証情報ファイル",
	FlagToken:       "OAuthトークンファイル",
	FlagState:       "状態ファイル",
	FlagAutoApprove: "確認をスキップ",
	FlagOutput:      "出力ファイル(未指定時は --file の値)",
	FlagLang:        "言語 (en, ja)",

	NoChanges:     "変更なし",
	NoChangesLong: "変更なし — フォームは最新です",
	FormInfo:      "フォーム情報:",
	DiffSummary:   "合計: +%d ~%d -%d",

	NewFormHeader: "新規フォーム作成:",
	CreateSummary: "合計: %d項目を作成",

	Creating:     "フォーム作成中...",
	Applied:      "適用完了!",
	Cancelled:    "キャンセルしました",
	ConfirmApply: "適用しますか?",
	FormIDLabel:  "  フォームID:  %s",
	URLLabel:     "  回答URL:     %s",
	StateLabel:   "  状態ファイル: %s",

	Imported:      "インポート完了!",
	SpecFileLabel: "  定義ファイル: %s",
	ItemCount:     "  項目数: %d",

	AuthBrowser:     "ブラウザで認証してください...",
	AuthSuccessHTML: "<h2>認証成功!</h2><p>このタブを閉じてターミナルに戻ってください。</p>",
	AuthFailedHTML:  "<h2>認証失敗</h2><p>認証コードが取得できませんでした。</p>",
	AuthCodeMissing: "認証コードが見つかりません",
	AuthTimeout:     "認証タイムアウト(2分)",
	AuthOpenURL:     "以下のURLをブラウザで開いてください:\n%s",

	ValErrors:      "バリデーションエラー (%d件):\n  %s",
	ValTitle:       "title は必須です",
	ValItems:       "items は1つ以上必要です",
	ValItemTitle:   "%s: title は必須です",
	ValItemType:    "%s: type は必須です",
	ValTypeUnknown: "%s: 不明な type %q (有効値: %s)",
	ValChoiceReq:   "%s: type=choice には choice フィールドが必須です",
	ValChoiceType:  "%s: 不明な choice.type %q (有効値: %s)",
	ValChoiceOpts:  "%s: choice.options は1つ以上必要です",
	ValChoiceEmpty: "%s: choice.options[%d] は空にできません",
	ValScaleReq:    "%s: type=scale には scale フィールドが必須です",
	ValScaleLow:    "%s: scale.low は 0 または 1 のみ (got %d)",
	ValScaleHigh:   "%s: scale.high は 2〜10 の範囲 (got %d)",
	ValScaleRange:  "%s: scale.low (%d) は scale.high (%d) より小さくなければなりません",

	ErrReadFile:    "ファイル読み込み失敗",
	ErrParseYAML:   "YAML解析失敗",
	ErrTitleReq:    "titleは必須です",
	ErrCredentials: "credentials読み込み失敗",
	ErrCredsParse:  "credentials解析失敗",
	ErrAuth:        "認証失敗",
	ErrTokenSave:   "トークン保存失敗",
	ErrFormsInit:   "Forms API初期化失敗",
	ErrFormCreate:  "フォーム作成失敗",
	ErrFormSetup:   "フォーム設定失敗",
	ErrFormGet:     "フォーム取得失敗",
	ErrFormUpdate:  "フォーム更新失敗",
	ErrLocalServer: "ローカルサーバー起動失敗",
	ErrStateSave:   "状態保存失敗",
	ErrStateRead:   "状態ファイル読み込み失敗",
	ErrSpecSave:    "定義ファイル保存失敗",
	ErrCredsHint:   "\n\nヒント: gcloud auth application-default login --scopes=%s,https://www.googleapis.com/auth/cloud-platform を実行するか、OAuth2 credentials.json を配置してください",
}

Ja is the Japanese message catalog.

var M = &En

M is the active message catalog. Use this to access localized strings.

Functions

func Set

func Set(l Lang)

Set switches the active language. It is safe to call concurrently.

Types

type Lang

type Lang string

Lang represents a supported language.

const (
	// EN selects English messages.
	EN Lang = "en"
	// JA selects Japanese messages.
	JA Lang = "ja"
)

Supported language codes.

func Get
func Get() Lang

Get returns the current language. It is safe to call concurrently.

type Messages

type Messages struct {
	// CLI descriptions used in cobra command help output.
	CmdLong     string
	PlanShort   string
	ApplyShort  string
	ImportShort string

	// Flag descriptions shown in --help output.
	FlagFile        string
	FlagCredentials string
	FlagToken       string
	FlagState       string
	FlagAutoApprove string
	FlagOutput      string
	FlagLang        string

	// Plan / Diff output messages.
	NoChanges     string
	NoChangesLong string
	FormInfo      string
	DiffSummary   string // "+%d ~%d -%d"

	// New form creation summary messages.
	NewFormHeader string
	CreateSummary string // "%d items to create"

	// Apply command progress and result messages.
	Creating     string
	Applied      string
	Cancelled    string
	ConfirmApply string
	FormIDLabel  string
	URLLabel     string
	StateLabel   string

	// Import command result messages.
	Imported      string
	SpecFileLabel string
	ItemCount     string

	// OAuth2 browser authentication messages.
	AuthBrowser     string
	AuthSuccessHTML string
	AuthFailedHTML  string
	AuthCodeMissing string
	AuthTimeout     string
	AuthOpenURL     string

	// Validation error messages (format strings with item prefix %s).
	ValErrors      string
	ValTitle       string
	ValItems       string
	ValItemTitle   string
	ValItemType    string
	ValTypeUnknown string
	ValChoiceReq   string
	ValChoiceType  string
	ValChoiceOpts  string
	ValChoiceEmpty string
	ValScaleReq    string
	ValScaleLow    string
	ValScaleHigh   string
	ValScaleRange  string

	// Error message fragments wrapped via fmt.Errorf.
	ErrReadFile    string
	ErrParseYAML   string
	ErrTitleReq    string
	ErrCredentials string
	ErrCredsParse  string
	ErrAuth        string
	ErrTokenSave   string
	ErrFormsInit   string
	ErrFormCreate  string
	ErrFormSetup   string
	ErrFormGet     string
	ErrFormUpdate  string
	ErrLocalServer string
	ErrStateSave   string
	ErrStateRead   string
	ErrSpecSave    string
	ErrCredsHint   string
}

Messages holds all user-facing strings for a given language. Each field corresponds to a distinct UI message; format strings follow the fmt package conventions (%s, %d, %q, %w).