docs » cp.strings.source.plist


Loads strings from a plist with allowing for a given language variation. Eg:

local plistSource = require("cp.strings.source.plist").new("/Path/To/Resources/${language}.lproj/MYLocalization.strings")
local value = plistSource:find("en", "AKey")

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

API Documentation

Constants

defaultCacheSeconds

Signature cp.strings.source.plist.defaultCacheSeconds
Type Constant
Description The default number of seconds to cache results.

Constructors

new

Signature cp.strings.source.plist.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](#defaultCacheSeconds)
Returns
  • The new plist `source` instance.

Methods

find

Signature cp.strings.source.plist:find(language, key) -> 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.

findKeys

Signature cp.strings.source.plist:findKeys(language, value) -> {string}
Type Method
Description Finds the array of keys with the matching value in the plist file for the specified language, if the plist can be found, and contains matching key.
Parameters
  • `language` - The language code to look for (e.g. `"en"`, or `"fr"`).
  • `value` - The value.
Returns
  • The array of keys, or `{}` if none were fround

loadFile

Signature cp.strings.source.plist:loadFile(language) -> string
Type Method
Description Loads the plist file for the specified language, returning the value as a table.
Parameters
  • `language` - The language code to look for (e.g. `"en"`, or `"fr"`).
Returns
  • The table for the specified language, or `nil` if the file doesn't exist.

pathToAbsolute

Signature cp.strings.source.plist:pathToAbsolute(language) -> string
Type Method
Description Finds the abolute path to the plist represented by this source for the specified langauge, or nil if it does not exist.
Parameters
  • `language` - The language code to look for (e.g. `"en"`, or `"fr"`).
Returns
  • The path to the file, or `nil` if not found.

reset

Signature cp.strings.source.plist:reset() -> cp.strings
Type Method
Description Clears any stored key values.
Parameters
  • None
Returns
  • The current `cp.strings` instance.

results matching ""

    No results matching ""