Documentation
¶
Index ¶
- Constants
- func GetLangFromContext(c *gin.Context) string
- func GetLocalizer(lang string) *i18n.Localizer
- func Init() error
- func IsSupported(lang string) bool
- func ParseAcceptLanguage(header string) string
- func SetUserLangLoader(loader func(userId int) string)
- func SupportedLanguages() []string
- func T(c *gin.Context, key string, args ...map[string]any) string
- func Translate(lang, key string, args ...map[string]any) string
Constants ¶
const ( LangZh = "zh" LangEn = "en" DefaultLang = LangEn // Fallback to English if language not supported )
const ( MsgInvalidParams = "common.invalid_params" MsgDatabaseError = "common.database_error" MsgRetryLater = "common.retry_later" MsgGenerateFailed = "common.generate_failed" MsgNotFound = "common.not_found" MsgForbidden = "common.forbidden" MsgInvalidId = "common.invalid_id" MsgIdEmpty = "common.id_empty" MsgFeatureDisabled = "common.feature_disabled" MsgOperationSuccess = "common.operation_success" MsgOperationFailed = "common.operation_failed" MsgUpdateSuccess = "common.update_success" MsgUpdateFailed = "common.update_failed" MsgCreateSuccess = "common.create_success" MsgCreateFailed = "common.create_failed" MsgDeleteSuccess = "common.delete_success" MsgDeleteFailed = "common.delete_failed" MsgAlreadyExists = "common.already_exists" MsgNameCannotBeEmpty = "common.name_cannot_be_empty" )
Common error messages
const ( MsgTokenNameTooLong = "token.name_too_long" MsgTokenQuotaNegative = "token.quota_negative" MsgTokenQuotaExceedMax = "token.quota_exceed_max" MsgTokenGenerateFailed = "token.generate_failed" MsgTokenGetInfoFailed = "token.get_info_failed" MsgTokenExpiredCannotEnable = "token.expired_cannot_enable" MsgTokenExhaustedCannotEable = "token.exhausted_cannot_enable" MsgTokenInvalid = "token.invalid" MsgTokenNotProvided = "token.not_provided" MsgTokenExpired = "token.expired" MsgTokenExhausted = "token.exhausted" MsgTokenDbError = "token.db_error" )
Token related messages
const ( MsgRedemptionNameLength = "redemption.name_length" MsgRedemptionCountPositive = "redemption.count_positive" MsgRedemptionCountMax = "redemption.count_max" MsgRedemptionCreateFailed = "redemption.create_failed" MsgRedemptionInvalid = "redemption.invalid" MsgRedemptionUsed = "redemption.used" MsgRedemptionExpired = "redemption.expired" MsgRedemptionFailed = "redemption.failed" MsgRedemptionNotProvided = "redemption.not_provided" MsgRedemptionExpireTimeInvalid = "redemption.expire_time_invalid" )
Redemption related messages
const ( MsgUserPasswordLoginDisabled = "user.password_login_disabled" MsgUserRegisterDisabled = "user.register_disabled" MsgUserPasswordRegisterDisabled = "user.password_register_disabled" MsgUserUsernameOrPasswordEmpty = "user.username_or_password_empty" MsgUserUsernameOrPasswordError = "user.username_or_password_error" MsgUserEmailOrPasswordEmpty = "user.email_or_password_empty" MsgUserExists = "user.exists" MsgUserNotExists = "user.not_exists" MsgUserDisabled = "user.disabled" MsgUserSessionSaveFailed = "user.session_save_failed" MsgUserRequire2FA = "user.require_2fa" MsgUserEmailVerificationRequired = "user.email_verification_required" MsgUserVerificationCodeError = "user.verification_code_error" MsgUserInputInvalid = "user.input_invalid" MsgUserNoPermissionSameLevel = "user.no_permission_same_level" MsgUserNoPermissionHigherLevel = "user.no_permission_higher_level" MsgUserCannotCreateHigherLevel = "user.cannot_create_higher_level" MsgUserCannotDeleteRootUser = "user.cannot_delete_root_user" MsgUserCannotDisableRootUser = "user.cannot_disable_root_user" MsgUserCannotDemoteRootUser = "user.cannot_demote_root_user" MsgUserAlreadyAdmin = "user.already_admin" MsgUserAlreadyCommon = "user.already_common" MsgUserAdminCannotPromote = "user.admin_cannot_promote" MsgUserOriginalPasswordError = "user.original_password_error" MsgUserInviteQuotaInsufficient = "user.invite_quota_insufficient" MsgUserTransferQuotaMinimum = "user.transfer_quota_minimum" MsgUserTransferSuccess = "user.transfer_success" MsgUserTransferFailed = "user.transfer_failed" MsgUserTopUpProcessing = "user.topup_processing" MsgUserRegisterFailed = "user.register_failed" MsgUserDefaultTokenFailed = "user.default_token_failed" MsgUserAffCodeEmpty = "user.aff_code_empty" MsgUserEmailEmpty = "user.email_empty" MsgUserGitHubIdEmpty = "user.github_id_empty" MsgUserDiscordIdEmpty = "user.discord_id_empty" MsgUserOidcIdEmpty = "user.oidc_id_empty" MsgUserWeChatIdEmpty = "user.wechat_id_empty" MsgUserTelegramIdEmpty = "user.telegram_id_empty" MsgUserTelegramNotBound = "user.telegram_not_bound" MsgUserLinuxDOIdEmpty = "user.linux_do_id_empty" )
User related messages
const ( MsgQuotaNegative = "quota.negative" MsgQuotaExceedMax = "quota.exceed_max" MsgQuotaInsufficient = "quota.insufficient" MsgQuotaWarningInvalid = "quota.warning_invalid" MsgQuotaThresholdGtZero = "quota.threshold_gt_zero" )
Quota related messages
const ( MsgSubscriptionNotEnabled = "subscription.not_enabled" MsgSubscriptionTitleEmpty = "subscription.title_empty" MsgSubscriptionPriceNegative = "subscription.price_negative" MsgSubscriptionPriceMax = "subscription.price_max" MsgSubscriptionPurchaseLimitNeg = "subscription.purchase_limit_negative" MsgSubscriptionQuotaNegative = "subscription.quota_negative" MsgSubscriptionGroupNotExists = "subscription.group_not_exists" MsgSubscriptionResetCycleGtZero = "subscription.reset_cycle_gt_zero" MsgSubscriptionPurchaseMax = "subscription.purchase_max" MsgSubscriptionInvalidId = "subscription.invalid_id" MsgSubscriptionInvalidUserId = "subscription.invalid_user_id" )
Subscription related messages
const ( MsgPaymentNotConfigured = "payment.not_configured" MsgPaymentMethodNotExists = "payment.method_not_exists" MsgPaymentCallbackError = "payment.callback_error" MsgPaymentCreateFailed = "payment.create_failed" MsgPaymentStartFailed = "payment.start_failed" MsgPaymentAmountTooLow = "payment.amount_too_low" MsgPaymentStripeNotConfig = "payment.stripe_not_configured" MsgPaymentWebhookNotConfig = "payment.webhook_not_configured" MsgPaymentPriceIdNotConfig = "payment.price_id_not_configured" MsgPaymentCreemNotConfig = "payment.creem_not_configured" )
Payment related messages
const ( MsgTopupNotProvided = "topup.not_provided" MsgTopupOrderNotExists = "topup.order_not_exists" MsgTopupOrderStatus = "topup.order_status" MsgTopupFailed = "topup.failed" MsgTopupInvalidQuota = "topup.invalid_quota" )
Topup related messages
const ( MsgChannelNotExists = "channel.not_exists" MsgChannelIdFormatError = "channel.id_format_error" MsgChannelNoAvailableKey = "channel.no_available_key" MsgChannelGetListFailed = "channel.get_list_failed" MsgChannelGetTagsFailed = "channel.get_tags_failed" MsgChannelGetKeyFailed = "channel.get_key_failed" MsgChannelGetOllamaFailed = "channel.get_ollama_failed" MsgChannelQueryFailed = "channel.query_failed" MsgChannelNoValidUpstream = "channel.no_valid_upstream" MsgChannelUpstreamSaturated = "channel.upstream_saturated" MsgChannelGetAvailableFailed = "channel.get_available_failed" )
Channel related messages
const ( MsgModelNameEmpty = "model.name_empty" MsgModelNameExists = "model.name_exists" MsgModelIdMissing = "model.id_missing" MsgModelGetListFailed = "model.get_list_failed" MsgModelGetFailed = "model.get_failed" MsgModelResetSuccess = "model.reset_success" )
Model related messages
const ( MsgVendorNameEmpty = "vendor.name_empty" MsgVendorNameExists = "vendor.name_exists" MsgVendorIdMissing = "vendor.id_missing" )
Vendor related messages
const ( MsgGroupNameTypeEmpty = "group.name_type_empty" MsgGroupNameExists = "group.name_exists" MsgGroupIdMissing = "group.id_missing" )
Group related messages
const ( MsgCheckinDisabled = "checkin.disabled" MsgCheckinAlreadyToday = "checkin.already_today" MsgCheckinFailed = "checkin.failed" MsgCheckinQuotaFailed = "checkin.quota_failed" )
Checkin related messages
const ( MsgPasskeyCreateFailed = "passkey.create_failed" MsgPasskeyLoginAbnormal = "passkey.login_abnormal" MsgPasskeyUpdateFailed = "passkey.update_failed" MsgPasskeyInvalidUserId = "passkey.invalid_user_id" MsgPasskeyVerifyFailed = "passkey.verify_failed" )
Passkey related messages
const ( MsgTwoFANotEnabled = "twofa.not_enabled" MsgTwoFAUserIdEmpty = "twofa.user_id_empty" MsgTwoFAAlreadyExists = "twofa.already_exists" MsgTwoFARecordIdEmpty = "twofa.record_id_empty" MsgTwoFACodeInvalid = "twofa.code_invalid" )
2FA related messages
const ( MsgRateLimitReached = "rate_limit.reached" MsgRateLimitTotalReached = "rate_limit.total_reached" )
Rate limit related messages
const ( MsgSettingInvalidType = "setting.invalid_type" MsgSettingWebhookEmpty = "setting.webhook_empty" MsgSettingWebhookInvalid = "setting.webhook_invalid" MsgSettingEmailInvalid = "setting.email_invalid" MsgSettingBarkUrlEmpty = "setting.bark_url_empty" MsgSettingBarkUrlInvalid = "setting.bark_url_invalid" MsgSettingGotifyUrlEmpty = "setting.gotify_url_empty" MsgSettingGotifyTokenEmpty = "setting.gotify_token_empty" MsgSettingGotifyUrlInvalid = "setting.gotify_url_invalid" MsgSettingUrlMustHttp = "setting.url_must_http" MsgSettingSaved = "setting.saved" )
Setting related messages
const ( MsgDeploymentNotEnabled = "deployment.not_enabled" MsgDeploymentIdRequired = "deployment.id_required" MsgDeploymentContainerIdReq = "deployment.container_id_required" MsgDeploymentNameEmpty = "deployment.name_empty" MsgDeploymentNameTaken = "deployment.name_taken" MsgDeploymentHardwareIdReq = "deployment.hardware_id_required" MsgDeploymentHardwareInvId = "deployment.hardware_invalid_id" MsgDeploymentApiKeyRequired = "deployment.api_key_required" MsgDeploymentInvalidPayload = "deployment.invalid_payload" MsgDeploymentNotFound = "deployment.not_found" )
Deployment related messages (io.net)
const ( MsgPerfDiskCacheCleared = "performance.disk_cache_cleared" MsgPerfStatsReset = "performance.stats_reset" MsgPerfGcExecuted = "performance.gc_executed" )
Performance related messages
const ( MsgAbilityDbCorrupted = "ability.db_corrupted" MsgAbilityRepairRunning = "ability.repair_running" )
Ability related messages
const ( MsgOAuthInvalidCode = "oauth.invalid_code" MsgOAuthGetUserErr = "oauth.get_user_error" MsgOAuthAccountUsed = "oauth.account_used" MsgOAuthUnknownProvider = "oauth.unknown_provider" MsgOAuthStateInvalid = "oauth.state_invalid" MsgOAuthNotEnabled = "oauth.not_enabled" MsgOAuthUserDeleted = "oauth.user_deleted" MsgOAuthUserBanned = "oauth.user_banned" MsgOAuthBindSuccess = "oauth.bind_success" MsgOAuthAlreadyBound = "oauth.already_bound" MsgOAuthConnectFailed = "oauth.connect_failed" MsgOAuthTokenFailed = "oauth.token_failed" MsgOAuthUserInfoEmpty = "oauth.user_info_empty" MsgOAuthTrustLevelLow = "oauth.trust_level_low" )
OAuth related messages
const ( MsgRedeemFailed = "redeem.failed" MsgCreateDefaultTokenErr = "user.create_default_token_error" MsgUuidDuplicate = "common.uuid_duplicate" MsgInvalidInput = "common.invalid_input" )
Model layer error messages (for translation in controller)
const ( MsgCustomOAuthNotFound = "custom_oauth.not_found" MsgCustomOAuthSlugEmpty = "custom_oauth.slug_empty" MsgCustomOAuthSlugExists = "custom_oauth.slug_exists" MsgCustomOAuthNameEmpty = "custom_oauth.name_empty" MsgCustomOAuthHasBindings = "custom_oauth.has_bindings" MsgCustomOAuthBindingNotFound = "custom_oauth.binding_not_found" MsgCustomOAuthProviderIdInvalid = "custom_oauth.provider_id_field_invalid" )
Custom OAuth provider related messages
Variables ¶
This section is empty.
Functions ¶
func GetLangFromContext ¶
GetLangFromContext extracts the language setting from gin context It checks multiple sources in priority order: 1. User settings (ContextKeyUserSetting) - if already loaded (e.g., by TokenAuth) 2. Lazy load user language from cache/DB using user ID 3. Language set by middleware (ContextKeyLanguage) - from Accept-Language header 4. Default language (English)
func GetLocalizer ¶
GetLocalizer returns a localizer for the specified language
func IsSupported ¶
IsSupported checks if a language code is supported
func ParseAcceptLanguage ¶
ParseAcceptLanguage parses the Accept-Language header and returns the preferred language
func SetUserLangLoader ¶
SetUserLangLoader sets the function to load user language (called from model package)
func SupportedLanguages ¶
func SupportedLanguages() []string
SupportedLanguages returns a list of supported language codes
Types ¶
This section is empty.