Skip to content

Commit

Permalink
[mikrobi#44][mikrobi#29] Using cultureKey instead of contextKey on Ba…
Browse files Browse the repository at this point in the history
…belTranslation snippet
  • Loading branch information
goldsky committed Nov 26, 2014
1 parent 42700a3 commit f1f60a6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions _build/data/properties/properties.babeltranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
'value' => '',
'lexicon' => 'babel:properties',
),
array(
'name' => 'cultureKey',
'desc' => 'babeltranslation.cultureKey',
'type' => 'textfield',
'options' => '',
'value' => '',
'lexicon' => 'babel:properties',
),
array(
'name' => 'showUnpublished',
'desc' => 'babeltranslation.showUnpublished',
Expand Down
1 change: 1 addition & 0 deletions core/components/babel/docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Changelog for Babel.

Babel 3.0.0-dev
==============
- [#44][#29] Using cultureKey instead of contextKey on BabelTranslation snippet
- [#70] fix is_folder to isfolder
- [#27][#90][#92] Refactor language selection, runs using AJAX
- [#83][#59] extend babel plugin OnResourceDuplicate for nested resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
* @package babel
*
* @param resourceId optional: id of resource of which a translated resource should be determined. Default: current resource
* @param contextKey Key of context in which translated resource should be determined.
* @param contextKey optional: Key of context in which translated resource should be determined.
* @param cultureKey optional: Key of culture in which translated resource should be determined. Used only in case contextKey was not specified. If both omitted: uses currently set cultureKey.
* @param showUnpublished optional: flag whether to show unpublished translations. Default: 0
*/
$babel = $modx->getService('babel','Babel',$modx->getOption('babel.core_path',null,$modx->getOption('core_path').'components/babel/').'model/babel/',$scriptProperties);
Expand All @@ -45,6 +46,10 @@
$resourceId = intval($modx->getOption('resourceId',$scriptProperties,$resourceId));
}
$contextKey = $modx->getOption('contextKey',$scriptProperties,'');
if (empty($contextKey)) {
$cultureKey = $modx->getOption('cultureKey',$scriptProperties,'');
$contextKey = $babel->getContextKey($cultureKey);
}
$showUnpublished = $modx->getOption('showUnpublished',$scriptProperties,0);

/* determine id of tranlated resource */
Expand Down
1 change: 1 addition & 0 deletions core/components/babel/lexicon/de/properties.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
/* BabelTranslation snippet */
$_lang['babeltranslation.resourceId'] = 'ID der Ressource, von der eine Übersetzung ermittelt werden soll';
$_lang['babeltranslation.contextKey'] = 'Schlüssel des Kontexts, in dem eine Übersetzung ermittelt werden soll';
$_lang['babeltranslation.cultureKey'] = 'Key of culture in which translated resource should be determined. Used only in case contextKey was not specified. If both omitted: uses currently set cultureKey.';
$_lang['babeltranslation.showUnpublished'] = 'Flag das betsimmt, ob unveröffentliche Übersetzungen angezeigt werden sollen';
1 change: 1 addition & 0 deletions core/components/babel/lexicon/fr/properties.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
/* BabelTranslation snippet */
$_lang['babeltranslation.resourceId'] = 'ID of resource of which a translated resource should be determined';
$_lang['babeltranslation.contextKey'] = 'Key of context in which translated resource should be determined';
$_lang['babeltranslation.cultureKey'] = 'Key of culture in which translated resource should be determined. Used only in case contextKey was not specified. If both omitted: uses currently set cultureKey.';
$_lang['babeltranslation.showUnpublished'] = 'Flag whether to show unpublished translations';
1 change: 1 addition & 0 deletions core/components/babel/lexicon/ro/properties.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
/* BabelTranslation snippet */
$_lang['babeltranslation.resourceId'] = 'IDul resursei de tradus';
$_lang['babeltranslation.contextKey'] = 'Cheia de context a resursei de tradus';
$_lang['babeltranslation.cultureKey'] = 'Key of culture in which translated resource should be determined. Used only in case contextKey was not specified. If both omitted: uses currently set cultureKey.';
$_lang['babeltranslation.showUnpublished'] = 'Afișează traducerile nepublicate';
15 changes: 15 additions & 0 deletions core/components/babel/model/babel/babel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,21 @@ public function removeLanguageLinksToContext($contextKey) {
}
}

/**
* Gets the contextKey by cultureKey
*
* @param string $cultureKey the culture key
* @return string context key
*/
public function getContextKey($cultureKey) {
/* Search for Context Setting */
$ctxSetting = $this->modx->getObject("modContextSetting", array(
"key" => "cultureKey",
"value" => $cultureKey
));
return (($ctxSetting)? $ctxSetting->get("context_key") : false);
}

/**
* Gets a Chunk and caches it; also falls back to file-based templates
* for easier debugging.
Expand Down

0 comments on commit f1f60a6

Please sign in to comment.