# 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. Notes: 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

Constants - Useful values which cannot be changed

  • defaultCacheSeconds

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

  • context
  • find
  • findKeys
  • loadFile
  • pathToAbsolute
  • reset

# API Documentation

# Constants

# defaultCacheSeconds

Signature cp.strings.source.plist.defaultCacheSeconds
Type Constant
Description The default number of seconds to cache results.
Notes None
Source src/extensions/cp/strings/source/plist.lua line 34

# Constructors

# new

Signature cp.strings.source.plist.new(pathPattern[, cacheSeconds]) -> 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.
Notes None
Examples None
Source src/extensions/cp/strings/source/plist.lua line 191

# Methods

# context

Signature cp.strings.source.plist:context([context]) -> table | self
Type Method
Description Gets or sets a context to be set for the source. This typically includes a language, which provides the default language code, but may have other source-specific properties. Calling this method may may clear caches, etc.
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.
Notes
  • For example:
  • lua</li><li>mySource:context({language = "fr"}) -- set the default language to French.</li><li>
Examples None
Source src/extensions/cp/strings/source/plist.lua line 39

# find

Signature cp.strings.source.plist:find(key[, context]) -> string
Type Method
Description Finds the specified key value in the plist, if the plist can be found, and contains matching key value.
Parameters
  • key - The key to retrieve from the file.
  • context - Optional table with additional/alternate context. It will be added to the current context temporarily.
Returns
  • The value of the key, or nil if not found.
Notes None
Examples None
Source src/extensions/cp/strings/source/plist.lua line 125

# findKeys

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | cp.strings.source.plist:findKeys(pattern) -> {string} | | Type | Method | | Description | Finds the array of keys who's value matches the pattern in this table. It will check that the pattern matches the beginning of the value. | | Parameters |

  • pattern - The string pattern to match.</li></ul> | | **Returns** | <ul><li>The array of keys, or ` if none were fround
| | Notes | None | | Examples | None | | Source | src/extensions/cp/strings/source/table.lua line 85 |


# loadFile

Signature cp.strings.source.plist:loadFile([context]) -> string
Type Method
Description Loads the plist file for the specified context, returning the value as a table.
Parameters
  • context - The context to determine the absolute path with. This will be added to any values provided in the default context.
Returns
  • The table for the specified language, or nil if the file doesn't exist.
Notes None
Examples None
Source src/extensions/cp/strings/source/plist.lua line 105

# pathToAbsolute

Signature cp.strings.source.plist:pathToAbsolute([context]) -> 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
  • context - The context to determine the absolute path with. This will be added to any values provided in the default context.
Returns
  • The path to the file, or nil if not found.
Notes None
Examples None
Source src/extensions/cp/strings/source/plist.lua line 65

# 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.
Notes None
Examples None
Source src/extensions/cp/strings/source/plist.lua line 177