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

Latest commit

 

History

History
96 lines (79 loc) · 8.36 KB

File metadata and controls

96 lines (79 loc) · 8.36 KB

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

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

Constructors

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.

Methods

| 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 | | 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.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.
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.
  • context - An optional additional context for the source.
Returns
  • The array of keys, or {} if none were fround
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.
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.
Signature cp.strings.source.plist:reset() -> cp.strings
Type Method
Description Clears any stored key values.
Parameters
  • None
Returns
  • The current cp.strings instance.