Class: Jekyll::UJTranslationUrlTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::UJTranslationUrlTag
- Defined in:
- lib/tags/translation_url.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ UJTranslationUrlTag
constructor
A new instance of UJTranslationUrlTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ UJTranslationUrlTag
6 7 8 9 |
# File 'lib/tags/translation_url.rb', line 6 def initialize(tag_name, markup, tokens) super @markup = markup.strip end |
Instance Method Details
#render(context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tags/translation_url.rb', line 11 def render(context) # Parse arguments that can be quoted or unquoted parts = parse_arguments(@markup) # Return root if no arguments return '/' if parts.empty? || parts[0].nil? language_code_input = parts[0] url_path_input = parts[1] || '/' # Resolve language code (literal or variable) language_code = resolve_argument_value(context, language_code_input) # Resolve URL path (literal or variable) url_path = resolve_argument_value(context, url_path_input) # Get site and translation config from context site = context.registers[:site] return '/' unless site translation_config = site.config['translation'] || {} default_language = translation_config['default'] || 'en' available_languages = translation_config['languages'] || [default_language] # Validate that the requested language is available unless available_languages.include?(language_code) # Fall back to default language if requested language is not available language_code = default_language end # Normalize the URL path normalized_path = normalize_path(url_path) # Generate the language-specific URL generate_language_url(language_code, normalized_path, default_language) end |