/** * @class ep.dict * */ /** * Get a translation for a keyword. * * ### Dependencies * * + `ep` * + `jQuery.dict` * + `jQuery.tmpl` * * @param {String} keyword A keyword to translate. * * @method translate * @member ep.dict * * @since 6.11.0 */ /** * Parse a text with keyword markers and translate them with the dictionary. * * ### Dependencies * * + `ep` * + `jQuery.dict` * + `jQuery.tmpl` * * @param {String} text A text with keyword markers to translate. * * @method parse * @member ep.dict * * @since 6.11.0 */ /** * Get a translation for a keyword and fill the data markers in translation. * * ### Dependencies * * + `ep` * + `jQuery.dict` * + `jQuery.tmpl` * * @param {String} keyword A keyword to translate. * @param {Object} data A key/value set to fill data markers in the translated keyword * * @method translateData * @member ep.dict * * @since 6.11.0 */ /** * Parse a text with keyword markers and translate them with the dictionary and fill the data markers in the parsed text. * * ### Dependencies * * + `ep` * + `jQuery.dict` * + `jQuery.tmpl` * * @param {String} text A text with keyword markers to translate. * @param {Object} data A key/value set to fill data markers in the translated parsed text. * * @method parseData * @member ep.dict * * @since 6.11.0 */ /** * Get a dictionary object for translation. * * Get a dictionary object for translation. * * ### Examples * Use an existing dictionary. * * JavaScript: * * // The example dictionary is already defined. * * // use default region/language * ep.dict( 'example' ); * * // use german * ep.dict( 'example', {region:'de'} ); * * Create a foo dictionary. * * JavaScript: * * // The example dictionary is already defined. * * // use default region/language * ep.dict( 'foo', [ 'example', {"strawberry":"Strawberry"} ] ); * * // use german * ep.dict( 'foo', [ 'example', {"strawberry":"Erdbeere"} ], {region:'de'} ); * * Translate keywors and parse text with a dict. * * JavaScript: * * var obj = ep.dict( 'ep.dict', {region:'de'} ); * * obj.translate('Close') * // * * * ### Dependencies * * + `ep` * + `jQuery.dict` * + `jQuery.tmpl` * * @param {String} name The name of the dictionary. * @param {Array} [data] An array containing names of other dictionaries, dictionary objects or a map of keyword/translation pairs to add. * @param {Object} [options] A map of additional options pass to the method. * @param {String} options.region A region/language to use for this dict. * @param {Array} options.parser An array of an regular expression to find translate keys and a match index. The match index setup which match will translate. * * @method constructor * @member ep.dict * * @since 6.11.0 */ /* * @copyright © Copyright 2006-2010, epages GmbH, All Rights Reserved. * * @module ep.dict * * @revision $Revision: 1.8 $ */ define("ep/dict", [ "jquery", "ep", "$dict!ep/dict", "jquery/dict", "jquery/tmpl" ], function ($, ep, epDict) { // Prevent fail of dictionay test case // backward compatible -> require module ep/dict expects $dict!ep/dict is also defined // epDict.translate('Save') $.each( ['translate', 'parse'], function( i, name ){ $.Dictionary.prototype[ name + 'Data' ] = function( key, data ){ return $.tmpl( '<span>' + this[ name ](key) + '</span>', [data] ) // replace key marker in translated string with given data .html() // get inner HTML .replace(/(^|[^ ])( )([^ ]|$)/g,"$1 $3"); // replace strange to regular space }; }); // set ep.dict as alias of $.dict ep.extend({ dict: $.dict }); return ep; });