Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 3.2 KB

File metadata and controls

42 lines (32 loc) · 3.2 KB

docs » cp.strings.source.table


Loads strings from provided tables, allowing for a given language variation. Eg:

local src = require("cp.strings.source.table").new():add("en", {foo = "bar"}):add("en", {foo = "baz"})
local valueEn = src:find("en", "foo") -- "bar"
local valueEs = src:find("en", "foo") -- "baz"

This will load the file for the specified language (replacing ${language} with "en" in the path) and return the value. Note: This will load the file on each request. To have values cached, use the cp.strings module and specify a plist as a source.

API Overview

  • Constructors - API calls which return an object, typically one that offers API methods
  • new
  • Methods - API calls which can only be made on an object returned by a constructor
  • find

API Documentation

Constructors

Signature cp.strings.source.table.new(language) -> source
Type Constructor
Description Creates a new cp.strings source that loads strings from a plist file.
Parameters
  • pathPattern - The path to load from. May contain a special ${language} marker which will be replace with the provided langauge when searching.
  • cacheSeconds - (optional) How long in seconds to keep the loaded values cached in memory. Defaults to defaultCacheSeconds
Returns
  • The new plist source instance.

Methods

Signature cp.strings.source.table:find(language) -> string
Type Method
Description Finds the specified key value in the plist file for the specified language, if the plist can be found, and contains matching key value.
Parameters
  • language - The language code to look for (e.g. "en", or "fr").
  • key - The key to retrieve from the file.
Returns
  • The value of the key, or nil if not found.