Skip to content

Commit

Permalink
Fix #34: New addLanguage method in AssetBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed May 3, 2015
1 parent 02ad8f7 commit 4f028d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions AssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ public function init() {
}
}

/**
* Adds a language JS locale file
*
* @param string $lang the ISO language code
* @param string $prefix the language locale file name prefix
* @param string $dir the language file directory relative to source path
* @param bool $min whether to auto use minified version
*
* @return AssetBundle instance
*/
public function addLanguage($lang = '', $prefix = '', $dir = null, $min = false)
{
if (empty($lang) || substr($lang, 0, 2) == 'en') {
return $this;
}
$ext = $min ? (YII_DEBUG ? ".min.js" : ".js") : ".js";
$file = "{$prefix}{$lang}{$ext}";
if ($dir === null) {
$dir = 'js';
} elseif ($dir === "/") {
$dir = '';
}
$path = $this->sourcePath . '/' . $dir;
if (!Config::fileExists("{$path}/{$file}")) {
$lang = Config::getLang($lang);
$file = "{$prefix}{$lang}{$ext}";
}
if (Config::fileExists("{$path}/{$file}")) {
$this->js[] = empty($dir) ? $file : "{$dir}/{$file}";
}
return $this;
}

/**
* Set up CSS and JS asset arrays based on the base-file names
*
Expand Down
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version 1.7.5
=============
**Date:** 02-Mar-2015
**Date:** 03-May-2015

- (enh #30): Improve translation trait for determining messages folder.
- (enh #33): Better styling of html5 inputs.
- (enh #34): New `addLanguage` method in `AssetBundle`.

version 1.7.4
=============
Expand Down

0 comments on commit 4f028d5

Please sign in to comment.