Skip to content

Commit

Permalink
Swap from variable magic string to actual magic string replace. Handl…
Browse files Browse the repository at this point in the history
…ed with internal LangOperations.
  • Loading branch information
Stikki committed Apr 13, 2014
1 parent 14c5a2d commit 7aa881f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ListIt2.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function ModLang()
{
$args = func_get_args();

return ListIt2LangOperations::lang_from_realm(LISTIT2, $args);
return ListIt2LangOperations::lang_from_realm(LISTIT2, $args, $this->GetName());
}

public function ModProcessTemplate($tpl_name)
Expand Down
33 changes: 14 additions & 19 deletions lang/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
/* Only necessary in the English lang file, because it's always loaded first, even English is not the user's language.
*/

if(is_object($modinstance)){

$module_name = $modinstance->GetName();
}
else {
// Here only for fallback
$module_name = LISTIT2;

$module_name = LISTIT2;
}
/* -- end of do not edit ------------------------------------------------ */

// global
Expand Down Expand Up @@ -360,8 +355,8 @@

// module
$lang['moddescription'] = 'ListItExtended allows you to create lists that you can display throughout your website.';
$lang['postinstall'] = $module_name . ' has successfully been installed';
$lang['postuninstall'] = $module_name . ' has successfully been uninstalled';
$lang['postinstall'] = '::INSTANCE_NAME:: has successfully been installed';
$lang['postuninstall'] = '::INSTANCE_NAME:: has successfully been uninstalled';

// module help
$lang['general'] = 'General';
Expand All @@ -381,8 +376,8 @@

$lang['help_usage'] = '<h3>Usage</h3>
<p>You can configure {$module_name} here: Content &raquo; {$module_name}</p>
<p>Place this tag in your page: {{$module_name}}</p><br />';
<p>You can configure ::INSTANCE_NAME:: here: Content &raquo; ::INSTANCE_NAME::</p>
<p>Place this tag in your page: {::INSTANCE_NAME::}</p><br />';

$lang['help_usage_options'] = 'After installing the module the next thing to do is set the options.
<ol>
Expand Down Expand Up @@ -411,12 +406,12 @@
$lang['help_permissions'] = '<h3>Permissions</h3>
<p>You can specify the following permissions under Users &amp; Groups &rarr; Group Permissions</p>
<ul>
<li>{$module_name}: Modify Items</li>
<li>{$module_name}: Modify all items</li>
<li>{$module_name}: Remove items</li>
<li>{$module_name}: Approve items</li>
<li>{$module_name}: Modify Categories</li>
<li>{$module_name}: Modify Options</li>
<li>::INSTANCE_NAME::: Modify Items</li>
<li>::INSTANCE_NAME::: Modify all items</li>
<li>::INSTANCE_NAME::: Remove items</li>
<li>::INSTANCE_NAME::: Approve items</li>
<li>::INSTANCE_NAME::: Modify Categories</li>
<li>::INSTANCE_NAME::: Modify Options</li>
</ul>
<p>To allow non-admin users to upload files, please go to Extensions > GBFilePicker and tick that first checkbox "Show filemanagement options".</p>';

Expand Down Expand Up @@ -490,12 +485,12 @@
Templates for your next project.</p>
<h4>Using Categories</h4>
<p>For detailed usage and available parameters, have a look below at "Parameters" Help section</p>
<pre><code>{{$module_name} action='category'}</code></pre>
<pre><code>{::INSTANCE_NAME:: action='category'}</code></pre>
EOT;

$lang['help_templates'] = '<h3>Templates</h3>
<p>If you are not sure what variables are available to use in your templates, try debugging:</p>
<p>{{$module_name} debug=1}</p>
<p>{::INSTANCE_NAME:: debug=1}</p>
<p>You can access any field directly when looping through items using its alias, for example, to if you created a field definition with an alias "position", you can do one of the following:</p>';

$lang['help_duplicating'] = '<h3>Creating Module Instances</h3>
Expand Down
18 changes: 14 additions & 4 deletions lib/class.ListIt2LangOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ class ListIt2LangOperations
{
private function __construct() {}

static final public function lang_from_realm($originator, $args)
static final public function lang_from_realm($originator, $args, $caller = FALSE)
{
global $CMS_VERSION;

$instance_name = $originator;
if($caller)
$instance_name = $caller;

if(version_compare($CMS_VERSION, '1.99-alpha0', '<')) {

$mod = cmsms()->GetModuleInstance($originator);
Expand All @@ -52,16 +56,22 @@ static final public function lang_from_realm($originator, $args)
$mod->LoadLangMethods();
array_unshift($args,'');
$args[0] = &$mod;

return call_user_func_array('cms_module_Lang', $args);
return self::clean_lang_string($instance_name, call_user_func_array('cms_module_Lang', $args));
}
else {

array_unshift($args,'');
$args[0] = $originator;

return CmsLangOperations::lang_from_realm($args);
return self::clean_lang_string($instance_name, CmsLangOperations::lang_from_realm($args));
}
}

static final public function clean_lang_string($replace, $string)
{
// All magic strings here, that should be replaced from lang strings.
return str_replace('::INSTANCE_NAME::', $replace, $string);
}

} // end of class

0 comments on commit 7aa881f

Please sign in to comment.