Class: Middleman::CoreExtensions::Internationalization
- Defined in:
- lib/middleman-more/core_extensions/i18n.rb
Defined Under Namespace
Modules: LocaleHelpers
Instance Attribute Summary
Attributes inherited from Extension
Instance Method Summary collapse
- #after_configuration ⇒ Object
-
#initialize(app, options_hash = {}, &block) ⇒ Internationalization
constructor
A new instance of Internationalization.
- #langs ⇒ Object
-
#manipulate_resource_list(resources) ⇒ void
Update the main sitemap resource list.
Methods inherited from Extension
activate, activated_extension, after_extension_activated, clear_after_extension_callbacks, config, extension_name, helpers, option, register
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ Internationalization
Returns a new instance of Internationalization.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/middleman-more/core_extensions/i18n.rb', line 10 def initialize(app, ={}, &block) super # See https://github.com/svenfuchs/i18n/wiki/Fallbacks unless [:no_fallbacks] require "i18n/backend/fallbacks" ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Fallbacks) end app.config.define_setting :locales_dir, "locales", 'The directory holding your locale configurations' app.send :include, LocaleHelpers end |
Instance Method Details
#after_configuration ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/middleman-more/core_extensions/i18n.rb', line 24 def after_configuration app.files.reload_path(app.config[:locals_dir] || [:data]) @locales_glob = File.join(app.config[:locals_dir] || [:data], "**", "*.{rb,yml,yaml}") @locales_regex = convert_glob_to_regex(@locales_glob) @maps = {} @mount_at_root = [:mount_at_root].nil? ? langs.first : [:mount_at_root] configure_i18n if !app.build? logger.info "== Locales: #{langs.join(", ")} (Default #{@mount_at_root})" end # Don't output localizable files app.ignore File.join([:templates_dir], "**") app.sitemap.(&method(:metadata_for_path)) app.files.changed(&method(:on_file_changed)) app.files.deleted(&method(:on_file_changed)) end |
#langs ⇒ Object
55 56 57 |
# File 'lib/middleman-more/core_extensions/i18n.rb', line 55 def langs @_langs ||= get_known_languages end |
#manipulate_resource_list(resources) ⇒ void
This method returns an undefined value.
Update the main sitemap resource list
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/middleman-more/core_extensions/i18n.rb', line 61 def manipulate_resource_list(resources) @_localization_data = {} new_resources = [] resources.each do |resource| # If it's a "localizable template" if File.fnmatch?(File.join([:templates_dir], "**"), resource.path) page_id = File.basename(resource.path, File.extname(resource.path)) langs.each do |lang| # Remove folder name path = resource.path.sub([:templates_dir], "") new_resources << build_resource(path, resource.path, page_id, lang) end elsif result = parse_locale_extension(resource.path) lang, path, page_id = result new_resources << build_resource(path, resource.path, page_id, lang) end end resources + new_resources end |