Skip to content

Load language packs from locale.ini instead of lang.php and locales.php #505

Open

Description

@caseysoftware

Today core includes two PHP files from every language folder. Replace them with one INI file read by parse_ini_file($file, false, INI_SCANNER_TYPED), which can't run code:

; web2project language pack
code          = "de_DE"     ; stored in user preferences and host_locale; must match ^[a-z]{2}_[A-Z]{2}$
name          = "German"    ; English name
native_name   = "Deutsch"
system_locale = "de_DE"     ; passed to setlocale() and the Gantt date locale
first_day     = 1           ; 0 = Sunday ... 6 = Saturday
core_version  = "6.0"       ; core release whose strings this pack targets
  • loadLanguages() builds the same $LANGUAGES array from locale.ini, so setUserLocale(), findLanguage() and the language pickers don't change.
  • loadLocale() (from Fall back to English when the user's or host language isn't installed #501) defines LOCALE_FIRST_DAY from first_day and stops including locales.php.
  • Charset is no longer per language: every pack is UTF-8, core passes <system_locale>.UTF-8 to setlocale(), and $locale_char_set stays set to utf-8 for the callers that read it.
  • LOCALE_TIME_FORMAT (and ru's LOCALE_DATE_FORMAT) is dropped; nothing reads it.

Validation when loading a pack: folder name matches ^[a-z]{2}(_[a-z]{2})?$; locale.ini parses; code matches its pattern; first_day is 0–6; names are non-empty and contain no markup. A pack that fails is left off the language list and the reason is logged. A folder with lang.php but no locale.ini is reported as "old format, not loaded". No .php file in a pack folder is ever included.

Part of #496.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions