Module: Jekyll::L10n::Constants
- Included in:
- Jekyll::L10n
- Defined in:
- lib/jekyll-l10n/constants.rb
Overview
Plugin Constants - Central definitions for magic values and configuration defaults
This module consolidates all constant values used throughout the jekyll-l10n plugin, eliminating magic numbers and string literals from the codebase. Constants are organized into logical groups: text validation, fallback modes, formatting, debugging, and defaults.
All constants are frozen to prevent accidental modification.
Constant Summary collapse
- MIN_TRANSLATABLE_LENGTH =
Minimum length for translatable text strings (shorter strings not extracted)
3- LOCALE_PATTERN =
Regular expression pattern for validating locale codes Matches ISO 639-1 (2 letter language) with optional ISO 3166-1 (2 letter country) Examples: ‘en’, ‘es’, ‘fr’, ‘pt_BR’, ‘zh_CN’
/^[a-z]{2}(_[A-Z]{2})?$/.freeze
- FALLBACK_MODE_ENGLISH =
Fallback mode: use original English text if translation not found
'english'- FALLBACK_MODE_MARKER =
Fallback mode: wrap untranslated text with markers (e.g., “[UNTRANSLATED] text”)
'marker'- FALLBACK_MODE_EMPTY =
Fallback mode: leave text blank if no translation found
'empty'- UNTRANSLATED_MARKER =
Marker used to indicate untranslated strings in marker fallback mode
'[UNTRANSLATED]'- PO_SHORT_LINE_LENGTH =
Line length threshold below which strings are rendered on a single line
80- PO_LINE_LENGTH =
Character chunk size for long strings (split across multiple lines). Must be kept in sync with the escape-sequence guard in PoFileWriter.format_long_string: when a chunk ends with an odd number of backslashes the trailing \ is the first byte of a \“ pair and the chunk is shrunk by 1 so the escape sequence is never split across lines. Splitting \” produces a dangling \ in the reader’s per-line unescape, which corrupts HTML attributes (e.g. target=“_blank\” instead of target=“_blank”).
70- LOG_THRESHOLD_SHORT =
Minimum text length to trigger logging (shorter strings are not logged)
50- LOG_TRUNCATE_SHORT =
Truncate length for key similarity logging (text)
20- LOG_TRUNCATE_MEDIUM =
Truncate length for text node previews (text)
40- LOG_TRUNCATE_LONG =
Truncate length for translation log messages (text)
60- BACKTRACE_CONTEXT_LENGTH =
Number of characters to show before/after difference in debug output
10- DEFAULT_LOCALES_DIR =
Default directory for storing PO translation files
'_locales'- DEFAULT_FALLBACK_MODE =
Default fallback mode when translation is not found
FALLBACK_MODE_ENGLISH- DEFAULT_TRANSLATABLE_ATTRIBUTES =
Default HTML attributes to extract from elements (can be overridden per-page)
%w[title alt aria-label placeholder aria-description].freeze
- DEFAULT_LIBRETRANSLATE_API_URL =
Default LibreTranslate API endpoint URL Uses localhost:5000 as default for local development
'http://localhost:5000'- DEFAULT_LIBRETRANSLATE_TIMEOUT =
Default timeout (in seconds) for LibreTranslate API requests
300- DEFAULT_LIBRETRANSLATE_BATCH_SIZE =
Default batch size for LibreTranslate API calls Controls how many strings are sent in a single request
50- DEFAULT_LIBRETRANSLATE_RETRY_ATTEMPTS =
Default number of retry attempts for failed LibreTranslate requests
3- DEFAULT_LIBRETRANSLATE_RETRY_DELAY =
Default delay (in seconds) between LibreTranslate retry attempts Exponential backoff is applied: actual_delay = base_delay * (2 ^ (attempt - 1))
2- DEFAULT_LIBRETRANSLATE_STOP_ON_ERROR =
Default behavior when LibreTranslate API returns an error If true, translation stops immediately. If false, continues with remaining entries.
false- DEFAULT_LIBRETRANSLATE_PROGRESS_INTERVAL =
Default interval for logging LibreTranslate translation progress Progress is logged every N entries. Set to 0 to disable.
10- DEFAULT_LIBRETRANSLATE_SOURCE_LOCALE =
Default source locale for LibreTranslate API The language of the original content being translated
'en'- DEFAULT_LIBRETRANSLATE_FORMAT =
Default text format for LibreTranslate API requests Either ‘text’ (plain text) or ‘html’ (preserves markup)
'html'