core/model/modx/modlexicon.class.php
MODX Revolution
Copyright 2006-2012 by MODX, LLC. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Package
- modx
\modLexicon
The lexicon handling class. Handles all lexicon topics by loading and storing their entries into a cached array.
Also considers database-based overrides for specific lexicon entries that preserve the originals and allow reversion.
Properties

array
$_lexicon= 'array()'
The actual language array.
array()Details- Type
- array
- Access
- protected
- Todo
- Separate into separate arrays for each namespace (and maybe topic) so that no namespacing in lexicon entries is needed. Maybe keep a master array of entries, but then have subarrays for topic-specific referencing.

array
$_loadedTopics= 'array()'
An array of loaded topic strings
array()Details- Type
- array

array
$_paths= 'array()'
Directories to search for language strings in.
array()Details- Type
- array
- Access
- protected
- Deprecated

\modX
$modx= 'null'
Reference to the MODX instance.
nullDetails- Type
- \modX
- Access
- protected
Methods

__construct(
\xPDO $modx, array $config
=
array()
)
:
voidCreates the modLexicon instance.
| Name | Type | Description |
|---|---|---|
| $modx | \xPDO | A reference to the modX instance. |
| $config | array | An array of configuration properties |
- Constructor

_parse(
string $str, array $params
)
:
stringParses a lexicon string, replacing placeholders with specified strings.
| Name | Type | Description |
|---|---|---|
| $str | string | The string to parse |
| $params | array | An associative array of keys to replace |
| Type | Description |
|---|---|
| string | The processed string |
- Access
- private

clear(
string $language
=
''
)
:
voidCompletely clears the lexicon
| Name | Type | Description |
|---|---|---|
| $language | string |

clearCache(
string $path
=
''
)
:
stringClears the lexicon cache for the specified path.
| Name | Type | Description |
|---|---|---|
| $path | string | The path to clear. |
| Type | Description |
|---|---|
| string | The results of the cache clearing. |
- Access
- public

exists(
string $index, $language
=
''
)
:
booleanReturns if the key exists in the lexicon.
| Name | Type | Description |
|---|---|---|
| $index | string | |
| $language |
| Type | Description |
|---|---|
| boolean | True if exists. |
- Access
- public

fetch(
string $prefix
=
'', boolean $removePrefix
=
false, string $language
=
''
)
:
arrayAccessor method for the lexicon array.
| Name | Type | Description |
|---|---|---|
| $prefix | string | If set, will only return the lexicon entries with this prefix. |
| $removePrefix | boolean | If true, will strip the prefix from the returned indexes |
| $language | string |
| Type | Description |
|---|---|
| array | The internal lexicon. |
- Access
- public

getCacheKey(
string $namespace
=
'core', string $topic
=
'default', string $language
=
''
)
:
stringReturn the cache key representing the specified lexicon topic.
| Name | Type | Description |
|---|---|---|
| $namespace | string | The namespace for the topic |
| $topic | string | The topic to grab |
| $language | string | The language for the topic |
| Type | Description |
|---|---|
| string | The cache key for the specified topic |
- Access
- public

getFileTopic(
string $language
=
'en', string $namespace
=
'core', string $topic
=
'default'
)
:
arrayGet entries from file-based lexicon topic
| Name | Type | Description |
|---|---|---|
| $language | string | The language to filter by. |
| $namespace | string | The namespace to filter by. |
| $topic | string | The topic to filter by. |
| Type | Description |
|---|---|
| array | An array of lexicon entries in key - value pairs for the specified filter. |

getLanguageList(
string $namespace
=
'core'
)
:
arrayGet a list of available languages for a Namespace.
| Name | Type | Description |
|---|---|---|
| $namespace | string | The Namespace to filter by. |
| Type | Description |
|---|---|
| array | An array of available languages |

getNamespacePath(
string $namespace
=
'core'
)
:
stringGet the path of the specified Namespace
| Name | Type | Description |
|---|---|---|
| $namespace | string | The key of the Namespace |
| Type | Description |
|---|---|
| string | The path for the Namespace |

getTopicList(
string $language
=
'en', string $namespace
=
'core'
)
:
arrayGet a list of available Topics when given a Language and Namespace.
| Name | Type | Description |
|---|---|---|
| $language | string | The language to filter by. |
| $namespace | string | The language to filter by. |
| Type | Description |
|---|---|
| array | An array of Topic names. |

load(
)
:
voidLoads a variable number of topic areas. They must reside as topicname.
inc.php files in their proper culture directory. Can load an infinite number of topic areas via a dynamic number of arguments.
They are loaded by language:namespace:topic, namespace:topic, or just topic. Examples: $modx->lexicon->load('en:core:snippet'); $modx->lexicon-
load ('demo:test'); $modx->lexicon->load('chunk');
- Access
- public

loadCache(
string $namespace
=
'core', string $topic
=
'default', string $language
=
''
)
:
arrayLoads a lexicon topic from the cache. If not found, tries to generate a cache file from the database.
| Name | Type | Description |
|---|---|---|
| $namespace | string | The namespace to load from. Defaults to 'core'. |
| $topic | string | The topic to load. Defaults to 'default'. |
| $language | string | The language to load. Defaults to 'en'. |
| Type | Description |
|---|---|
| array | The loaded lexicon array. |
- Access
- public

process(
string $key, array $params
=
array(), string $language
=
''
)
:
stringGet a lexicon string by its index.
| Name | Type | Description |
|---|---|---|
| $key | string | The key of the lexicon string. |
| $params | array | An assocative array of placeholder keys and values to parse |
| $language | string |
| Type | Description |
|---|---|
| string | The text of the lexicon key, blank if not found. |
- Access
- public

set(
string | array $keys, string $text
=
'', string $language
=
''
)
:
voidSets a lexicon key to a value. Not recommended, since doesn't query the database.
| Name | Type | Description |
|---|---|---|
| $keys | string | array | Either an array of array pairs of key/values or a key string. |
| $text | string | The text to set, if the first parameter is a string. |
| $language | string | The language to set the key in. Defaults to current. |
- Access
- public