today_ai_weather/config/initializers/locale.rb
songtianlun f6b9dcf187 feat: add internationalization support
- Implement locale extraction and fallback mechanism
- Add translation files for English and Chinese
- Update views to use translated strings for various UI elements

This commit introduces support for multiple languages in the application, enhancing accessibility for users. It includes a fallback mechanism for locales and updates to the user interface to display translated content.
2025-02-21 17:51:25 +08:00

20 lines
609 B
Ruby

# config/initializers/locale.rb
require "i18n/backend/fallbacks"
# Where the I18n library should search for translation files
I18n.load_path += Dir[Rails.root.join("config", "locales", "*.{rb,yml}")]
# Permitted locales available for the application
I18n.available_locales = [ :en, :"zh-CN" ]
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
# I18n::Backend::Simple.include I18n::Backend::Fallbacks
# I18n.fallbacks[:en]
I18n.fallbacks = I18n::Locale::Fallbacks.new(
en: [ :en ],
'zh-CN': [ :zh, :zh_cn, :en ]
)
# Set default locale to something other than :en
I18n.default_locale = :en