Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Latest commit

 

History

History
60 lines (48 loc) · 4.31 KB

cp.strings.source.table.md

File metadata and controls

60 lines (48 loc) · 4.31 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
  • add
  • context
  • find

API Documentation

Constructors

Signature cp.strings.source.table.new(context) -> source
Type Constructor
Description Creates a new cp.strings source that loads strings from a plist file.
Parameters
  • None
Returns
  • The new plist source instance.

Methods

Signature cp.strings.source.table:add(keyValues) -> self
Type Method
Description Adds the specified table of key values in the specified language code.
Parameters
  • keyValues - The table of key/value pairs to define.
Returns
  • The cp.string.source.

| Signature | cp.strings.source.table:context([context]) -> table | self | | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Gets or sets a context to be set for the source. This typically includes a language, which | | Parameters |

  • context - A table with values which may be used by the source.
| | Returns |
  • If a new context is provided, the cp.string.source is returned, otherwise the current context table is returned.
|

Signature cp.strings.source.table:find(key) -> string
Type Method
Description Finds the specified key value in the plist file for the specified optional context,
Parameters
  • key - The key to retrieve the value for.
  • context - An optional table with additional context.
Returns
  • The value of the key, or nil if not found.