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)

Returns:

  • (Integer)

    Always 3

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’

Returns:

  • (Regexp)
/^[a-z]{2}(_[A-Z]{2})?$/.freeze
FALLBACK_MODE_ENGLISH =

Fallback mode: use original English text if translation not found

Returns:

  • (String)

    “english”

'english'
FALLBACK_MODE_MARKER =

Fallback mode: wrap untranslated text with markers (e.g., “[UNTRANSLATED] text”)

Returns:

  • (String)

    “marker”

'marker'
FALLBACK_MODE_EMPTY =

Fallback mode: leave text blank if no translation found

Returns:

  • (String)

    “empty”

'empty'
UNTRANSLATED_MARKER =

Marker used to indicate untranslated strings in marker fallback mode

Returns:

  • (String)

    “[UNTRANSLATED]”

'[UNTRANSLATED]'
PO_SHORT_LINE_LENGTH =

Line length threshold below which strings are rendered on a single line

Returns:

  • (Integer)

    80

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”).

Returns:

  • (Integer)

    70

70
LOG_THRESHOLD_SHORT =

Minimum text length to trigger logging (shorter strings are not logged)

Returns:

  • (Integer)

    50

50
LOG_TRUNCATE_SHORT =

Truncate length for key similarity logging (text)

Returns:

  • (Integer)

    20

20
LOG_TRUNCATE_MEDIUM =

Truncate length for text node previews (text)

Returns:

  • (Integer)

    40

40
LOG_TRUNCATE_LONG =

Truncate length for translation log messages (text)

Returns:

  • (Integer)

    60

60
BACKTRACE_CONTEXT_LENGTH =

Number of characters to show before/after difference in debug output

Returns:

  • (Integer)

    10

10
DEFAULT_LOCALES_DIR =

Default directory for storing PO translation files

Returns:

  • (String)

    “_locales”

'_locales'
DEFAULT_FALLBACK_MODE =

Default fallback mode when translation is not found

Returns:

  • (String)

    “english”

FALLBACK_MODE_ENGLISH
DEFAULT_TRANSLATABLE_ATTRIBUTES =

Default HTML attributes to extract from elements (can be overridden per-page)

Returns:

  • (Array<String>)
    “title”, “alt”, “aria-label”, “placeholder”, “aria-description”
%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

Returns:

'http://localhost:5000'
DEFAULT_LIBRETRANSLATE_TIMEOUT =

Default timeout (in seconds) for LibreTranslate API requests

Returns:

  • (Integer)

    300 seconds (5 minutes)

300
DEFAULT_LIBRETRANSLATE_BATCH_SIZE =

Default batch size for LibreTranslate API calls Controls how many strings are sent in a single request

Returns:

  • (Integer)

    50

50
DEFAULT_LIBRETRANSLATE_RETRY_ATTEMPTS =

Default number of retry attempts for failed LibreTranslate requests

Returns:

  • (Integer)

    3

3
DEFAULT_LIBRETRANSLATE_RETRY_DELAY =

Default delay (in seconds) between LibreTranslate retry attempts Exponential backoff is applied: actual_delay = base_delay * (2 ^ (attempt - 1))

Returns:

  • (Integer)

    2 seconds

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.

Returns:

  • (Boolean)

    false

false
DEFAULT_LIBRETRANSLATE_PROGRESS_INTERVAL =

Default interval for logging LibreTranslate translation progress Progress is logged every N entries. Set to 0 to disable.

Returns:

  • (Integer)

    10 (log every 10 entries)

10
DEFAULT_LIBRETRANSLATE_SOURCE_LOCALE =

Default source locale for LibreTranslate API The language of the original content being translated

Returns:

  • (String)

    “en” (English)

'en'
DEFAULT_LIBRETRANSLATE_FORMAT =

Default text format for LibreTranslate API requests Either ‘text’ (plain text) or ‘html’ (preserves markup)

Returns:

  • (String)

    “html”

'html'