Skip to content

API Lang

Dory Azar edited this page Nov 25, 2026 · 5 revisions

Caligrafy\Lang

Caligrafy Quill 2.32.0. Generated from the source by php qa/build-api-reference.php; the guides explain how to use these classes, this reference says exactly what each public method takes and returns. Back to the API reference.

Part of Other classes.

namespace Caligrafy;

class Lang

Source: framework/core/Lang.php:28

Lang.php The languages of an application (2.28.0): its words in one file per language, the visitor's language, right to left

Constants

  • RTL = array('ar', 'arc', 'ckb', 'dv', 'fa', 'he', 'ku', 'ps', 'sd', 'ug', 'ur', 'yi')
  • COOKIE = 'lang'

Public properties

  • public static $path = null: string|null where the files are; null: application/lang (tests point it elsewhere)
  • public static $cookie = null: callable|null test hook: fn($name, $value, $options) instead of setcookie

Methods

Lang::locales()

public static function locales()

The languages of the app: APP_LOCALES, lowercased, in its order (en when empty)

Source: framework/core/Lang.php:46

Lang::fallback()

public static function fallback()

The language used when none is asked for: APP_LOCALE when it is one of the app's, else the first of APP_LOCALES

Source: framework/core/Lang.php:61

Lang::locale()

public static function locale()

The language of this request (found once: the address, the cookie, the browser, then the fallback)

Source: framework/core/Lang.php:75

Lang::set()

public static function set($code)

Uses a language for the rest of the request (a job writing to a person in theirs); false when it is not one of the app's

Parameters

  • $code

Source: framework/core/Lang.php:87

Lang::remember()

public static function remember($code)

Uses a language and remembers it in the visitor's cookie for a year (a language menu)

Parameters

  • $code

Source: framework/core/Lang.php:100

Lang::dir()

public static function dir($code = null)

rtl or ltr: the direction a language is written in (this request's when none is given)

Parameters

  • $code, default null

Source: framework/core/Lang.php:118

Lang::get()

public static function get($key, array $vars = array(), $code = null)

A word of the app in this request's language (or $code's): its file, then the fallback's, then the key itself. $vars replace {name}; a count picks a form of "one|other" or "zero|one|other"

Parameters

  • $key
  • $vars array, default array()
  • $code, default null

Source: framework/core/Lang.php:128

Lang::has()

public static function has($key, $code = null)

Whether the language (this request's when none is given) has that word in its own file

Parameters

  • $key
  • $code, default null

Source: framework/core/Lang.php:161

Lang::group()

public static function group($prefix, $code = null)

The words under a key, without it: group('validation') gives ['required' => ...]. The fallback's fill the gaps

Parameters

  • $prefix
  • $code, default null

Source: framework/core/Lang.php:169

Lang::all()

public static function all($code = null)

Every word of a language (the fallback's under it), flattened: for a page's script (lang_json())

Parameters

  • $code, default null

Source: framework/core/Lang.php:187

Lang::url()

public static function url($code, $uri = null)

The address of this page in another language (?lang=<code>, the rest of the query kept)

Parameters

  • $code
  • $uri, default null

Source: framework/core/Lang.php:196

Lang::money()

public static function money($amount, $currency, $code = null)

An amount of money in a language's way: "$1,234.50", "1 234,50 €", "١٬٢٣٤٫٥٠ US$" (intl), else "1,234.50 USD"

Parameters

  • $amount
  • $currency
  • $code, default null

Source: framework/core/Lang.php:209

Lang::number()

public static function number($value, $decimals = 0, $code = null)

A number in a language's way ("1,234.5", "1 234,5")

Parameters

  • $value
  • $decimals, default 0
  • $code, default null

Source: framework/core/Lang.php:227

Lang::date()

public static function date($value, $style = 'medium', $code = null, $timezone = null)

A date (a timestamp or a date string) in a language's way: short, medium, long or full (intl), else "25 Nov 2026"

Parameters

  • $value
  • $style, default 'medium'
  • $code, default null
  • $timezone, default null

Source: framework/core/Lang.php:244

Lang::reset()

public static function reset()

Forgets the request's language and the words read (tests, a long-running worker between requests)

Source: framework/core/Lang.php:265

Lang::words()

public static function words($code)

The words of a language, flattened (home.title), read once from application/lang/<code>.json. A file that is not valid JSON gives none (doctor says why)

Parameters

  • $code

Source: framework/core/Lang.php:275

Lang::file()

public static function file($code)

The file of a language: application/lang/<code>.json (or $path)

Parameters

  • $code

Source: framework/core/Lang.php:296

Lang::validatorLanguage()

public static function validatorLanguage()

The language GUMP speaks for the validator: this request's when GUMP has it (vendor/wixel/gump/lang), else en

Source: framework/core/Lang.php:308

Lang::fromAcceptLanguage()

public static function fromAcceptLanguage($header, array $locales)

The app's language the browser prefers (fr-CA;q=0.9 matches fr), or null

Parameters

  • $header
  • $locales array

Source: framework/core/Lang.php:346

Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.

Start here

Why Caligrafy: the benefits, the measurements, and what it is not yet

  1. Quickstart with Claude: describe it, approve it, ship it

    or the Quickstart: the same three steps by hand, in 5 minutes

  2. How Caligrafy works: the ideas in 5 minutes
  3. Your first capability: build a feature, page included

Capabilities

Experiences

Data and people

  1. Models
  2. Relationships
  3. Queries: filters, paging, related rows
  4. Sign-in, users and tokens

Built-in features

Put it online

Build with AI

Reference

Clone this wiki locally