Commit 78457bf0 by Qiang Xue

fetching plural rule data.

parent 2026d382
deny from all
#!/usr/bin/env php
<?php
/**
* build script file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require(__DIR__ . '/../framework/yii.php');
$id = 'yiic-build';
$basePath = __DIR__;
$application = new yii\console\Application($id, $basePath);
$application->run();
@echo off
rem -------------------------------------------------------------
rem build script for Windows.
rem
rem This is the bootstrap script for running build on Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/
rem @version $Id$
rem -------------------------------------------------------------
@setlocal
set BUILD_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
%PHP_COMMAND% "%BUILD_PATH%build" %*
@endlocal
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Phing build file for Yii.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2009 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
-->
<project name="yii" basedir="." default="help">
<!-- task definitions -->
<taskdef name="yii-init-build" classname="YiiInitTask" classpath="tasks" />
<!--
<taskdef name="yii-pear" classname="YiiPearTask" classpath="tasks"/>
-->
<!-- init yii.version, yii.revision and yii.winbuild -->
<yii-init-build />
<!-- these are required external commands -->
<property name="php" value="php" /> <!-- PHP parser -->
<property name="hhc" value="hhc" /> <!-- compile phpdoc into CHM -->
<property name="pdflatex" value="pdflatex" /> <!-- generates PDF from LaTex -->
<property name="pkgname" value="${phing.project.name}-${yii.version}.${yii.revision}"/>
<property name="docname" value="${phing.project.name}-docs-${yii.version}.${yii.revision}"/>
<property name="pearname" value="${phing.project.name}-${yii.release}.tgz" />
<!-- directory definitions -->
<property name="build.base.dir" value="release"/>
<property name="build.dist.dir" value="${build.base.dir}/dist"/>
<property name="build.src.dir" value="${build.base.dir}/${pkgname}"/>
<property name="build.pear.src.dir" value="${build.src.dir}/framework" />
<property name="build.doc.dir" value="${build.base.dir}/${docname}"/>
<property name="build.web.dir" value="${build.base.dir}/web"/>
<tstamp>
<format property="DATE" pattern="%b %e %Y" />
</tstamp>
<if>
<equals arg1="${yii.winbuild}" arg2="true"/>
<then>
<property name="build" value="build"/>
</then>
<else>
<property name="build" value="php build"/>
</else>
</if>
<!-- source files in the framework -->
<fileset dir=".." id="framework">
<exclude name="**/.gitignore"/>
<exclude name="**/*.bak"/>
<exclude name="**/*~"/>
<include name="framework/**/*"/>
<include name="requirements/**/*"/>
<include name="demos/**/*"/>
<include name="CHANGELOG"/>
<include name="UPGRADE"/>
<include name="LICENSE"/>
<include name="README"/>
</fileset>
<!-- doc files -->
<fileset dir="../docs" id="docs">
<exclude name="**/.gitignore"/>
<exclude name="**/*.bak"/>
<exclude name="**/*~"/>
<include name="guide/**/*"/>
<include name="blog/**/*"/>
</fileset>
<fileset dir="../docs/guide" id="docs-guide">
<exclude name="**/.gitignore"/>
<exclude name="**/*.bak"/>
<exclude name="**/*~"/>
<include name="**/*"/>
</fileset>
<fileset dir="../docs/blog" id="docs-blog">
<exclude name="**/.gitignore"/>
<exclude name="**/*.bak"/>
<exclude name="**/*~"/>
<include name="**/*"/>
</fileset>
<fileset dir="." id="writables">
<include name="${build.src.dir}/**/runtime" />
<include name="${build.src.dir}/**/assets" />
<include name="${build.src.dir}/demos/**/data" />
</fileset>
<fileset dir="." id="executables">
<include name="${build.src.dir}/**/yiic" />
</fileset>
<target name="src" depends="sync">
<echo>Building package ${pkgname}...</echo>
<echo>Copying files to build directory...</echo>
<copy todir="${build.src.dir}">
<fileset refid="framework"/>
</copy>
<echo>Changing file permissions...</echo>
<chmod mode="0777">
<fileset refid="writables" />
</chmod>
<chmod mode="0755">
<fileset refid="executables" />
</chmod>
<echo>Generating source release file...</echo>
<mkdir dir="${build.dist.dir}" />
<if>
<equals arg1="${yii.winbuild}" arg2="true"/>
<then>
<tar destfile="${build.dist.dir}/${pkgname}.tar.gz" compression="gzip">
<fileset dir="${build.base.dir}">
<include name="${pkgname}/**/*"/>
</fileset>
</tar>
</then>
<else>
<exec command="tar czpf ${pkgname}.tar.gz ${pkgname}" dir="${build.base.dir}"/>
<move file="${build.base.dir}/${pkgname}.tar.gz" todir="${build.dist.dir}" />
</else>
</if>
<zip destfile="${build.dist.dir}/${pkgname}.zip">
<fileset dir="${build.base.dir}">
<include name="${pkgname}/**/*"/>
</fileset>
</zip>
</target>
<target name="doc" depends="sync">
<echo>Building documentation...</echo>
<echo>Building Guide PDF...</echo>
<exec command="${build} guideLatex" dir="." passthru="true" />
<exec command="${pdflatex} guide.tex -interaction=nonstopmode -max-print-line=120" dir="commands/guide" passthru="true"/>
<exec command="${pdflatex} guide.tex -interaction=nonstopmode -max-print-line=120" dir="commands/guide" passthru="true"/>
<exec command="${pdflatex} guide.tex -interaction=nonstopmode -max-print-line=120" dir="commands/guide" passthru="true"/>
<move file="commands/guide/guide.pdf" tofile="${build.doc.dir}/yii-guide-${yii.version}.pdf" />
<echo>Building Blog PDF...</echo>
<exec command="${build} blogLatex" dir="." passthru="true" />
<exec command="${pdflatex} blog.tex -interaction=nonstopmode -max-print-line=120" dir="commands/blog" passthru="true"/>
<exec command="${pdflatex} blog.tex -interaction=nonstopmode -max-print-line=120" dir="commands/blog" passthru="true"/>
<exec command="${pdflatex} blog.tex -interaction=nonstopmode -max-print-line=120" dir="commands/blog" passthru="true"/>
<move file="commands/blog/blog.pdf" tofile="${build.doc.dir}/yii-blog-${yii.version}.pdf" />
<echo>Building API...</echo>
<exec command="${build} api ${build.doc.dir}" dir="." passthru="true" />
<!--
<echo>Building API CHM...</echo>
<exec command="${hhc} ${build.doc.dir}/api/manual.hhp" />
<move file="${build.doc.dir}/api/manual.chm" tofile="${build.doc.dir}/yii-api-${yii.version}.chm" />
<delete>
<fileset dir="${build.doc.dir}/api">
<include name="manual.*" />
</fileset>
</delete>
-->
<echo>Generating doc release file...</echo>
<mkdir dir="${build.dist.dir}" />
<tar destfile="${build.dist.dir}/${docname}.tar.gz" compression="gzip">
<fileset dir="${build.base.dir}">
<include name="${docname}/**/*"/>
</fileset>
</tar>
<zip destfile="${build.dist.dir}/${docname}.zip">
<fileset dir="${build.base.dir}">
<include name="${docname}/**/*"/>
</fileset>
</zip>
</target>
<target name="web" depends="sync">
<echo>Building online API...</echo>
<mkdir dir="${build.web.dir}/common/data/${yii.version}" />
<exec command="${build} api ${build.web.dir}/common/data/${yii.version} online" dir="." passthru="true" />
<echo>Copying tutorials...</echo>
<copy todir="${build.web.dir}/common/data/${yii.version}/tutorials/guide">
<fileset refid="docs-guide"/>
</copy>
<copy todir="${build.web.dir}/common/data/${yii.version}/tutorials/blog">
<fileset refid="docs-blog"/>
</copy>
<echo>Copying release text files...</echo>
<mkdir dir="${build.web.dir}/frontend/www/files" />
<copy file="../CHANGELOG" tofile="${build.web.dir}/frontend/www/files/CHANGELOG-${yii.version}.txt" />
<copy file="../UPGRADE" tofile="${build.web.dir}/frontend/www/files/UPGRADE-${yii.version}.txt" />
<echo>
Finished building Web files.
Please update yiisite/common/data/versions.php file with the following code:
'1.1'=>array(
'version'=>'${yii.version}',
'revision'=>'${yii.revision}',
'date'=>'${yii.date}',
'latest'=>true,
),
</echo>
</target>
<target name="sync">
<echo>Synchronizing code changes for ${pkgname}...</echo>
<echo>Building autoload map...</echo>
<exec command="${build} autoload" dir="." passthru="true"/>
<echo>Building yiilite.php...</echo>
<exec command="${build} lite" dir="." passthru="true"/>
</target>
<target name="message">
<echo>Extracting i18n messages...</echo>
<exec command="${build} message ../framework/messages/config.php" dir="." passthru="true"/>
</target>
<!--
<target name="pear" depends="clean,build">
<echo>Generating pear package for ${phing.project.name}-${yii.release}</echo>
<mkdir dir="${build.dist.dir}" />
<yii-pear pkgdir="${build.pear.src.dir}"
channel="pear.php.net"
version="${yii.release}"
state="stable"
category="framework"
package="${phing.project.name}"
summary="Yii PHP Framework"
pkgdescription="Yii PHP Framework: Best for Web 2.0 Development"
notes="http://www.yiiframework.com/files/CHANGELOG-${yii.release}.txt"
license="BSD"
/>
<exec command="pear package" dir="${build.pear.src.dir}" passthru="true" />
<move file="${build.pear.src.dir}/${pearname}" tofile="${build.dist.dir}/${pearname}" />
</target>
-->
<target name="clean">
<echo>Cleaning up the build...</echo>
<delete dir="${build.base.dir}"/>
</target>
<target name="help">
<echo>
Welcome to use Yii build script!
--------------------------------
You may use the following command format to build a target:
phing &lt;target name&gt;
where &lt;target name&gt; can be one of the following:
- sync : synchronize yiilite.php and YiiBase.php
- message : extract i18n messages of the framework
- src : build source release
- doc : build documentation release (Windows only)
- clean : clean up the build
</echo>
</target>
</project>
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
use yii\console\Controller;
use yii\helpers\FileHelper;
/**
* http://www.unicode.org/cldr/charts/supplemental/language_plural_rules.html
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class LocaleController extends Controller
{
public $defaultAction = 'plural';
/**
* Generates the plural rules data.
*
* This command will parse the plural rule XML file from CLDR and convert them
* into appropriate PHP representation to support Yii message translation feature.
* @param string $xmlFile the original plural rule XML file (from CLDR). This file may be found in
* http://www.unicode.org/Public/cldr/latest/core.zip
* Extract the zip file and locate the file "common/supplemental/plurals.xml".
* @throws Exception
*/
public function actionPlural($xmlFile)
{
if (!is_file($xmlFile)) {
throw new Exception("The source plural rule file does not exist: $xmlFile");
}
$xml = simplexml_load_file($xmlFile);
$allRules = array();
$patterns = array(
'/n in 0..1/' => '(n==0||n==1)',
'/\s+is\s+not\s+/i' => '!=', //is not
'/\s+is\s+/i' => '==', //is
'/n\s+mod\s+(\d+)/i' => 'fmod(n,$1)', //mod (CLDR's "mod" is "fmod()", not "%")
'/^(.*?)\s+not\s+(?:in|within)\s+(\d+)\.\.(\d+)/i' => '($1<$2||$1>$3)', //not in, not within
'/^(.*?)\s+within\s+(\d+)\.\.(\d+)/i' => '($1>=$2&&$1<=$3)', //within
'/^(.*?)\s+in\s+(\d+)\.\.(\d+)/i' => '($1>=$2&&$1<=$3&&fmod($1,1)==0)', //in
);
foreach ($xml->plurals->pluralRules as $node) {
$attributes = $node->attributes();
$locales = explode(' ', $attributes['locales']);
$rules = array();
if (!empty($node->pluralRule)) {
foreach ($node->pluralRule as $rule) {
$expr_or = preg_split('/\s+or\s+/i', $rule);
foreach ($expr_or as $key_or => $val_or) {
$expr_and = preg_split('/\s+and\s+/i', $val_or);
$expr_and = preg_replace(array_keys($patterns), array_values($patterns), $expr_and);
$expr_or[$key_or] = implode('&&', $expr_and);
}
$rules[] = preg_replace('/\\bn\\b/', '$n', implode('||', $expr_or));
}
foreach ($locales as $locale) {
$allRules[$locale] = $rules;
}
}
}
// hard fix for "br": the rule is too complex
$allRules['br'] = array(
0 => 'fmod($n,10)==1&&!in_array(fmod($n,100),array(11,71,91))',
1 => 'fmod($n,10)==2&&!in_array(fmod($n,100),array(12,72,92))',
2 => 'in_array(fmod($n,10),array(3,4,9))&&!in_array(fmod($n,100),array_merge(range(10,19),range(70,79),range(90,99))))',
3 => 'fmod($n,1000000)==0&&$n!=0',
);
if (preg_match('/\d+/', $xml->version['number'], $matches)) {
$revision = $matches[0];
} else {
$revision = -1;
}
echo "<?php\n";
echo <<<EOD
/**
* Plural rules.
*
* This file is automatically generated by the "yiic locale/plural" command under the "build" folder.
* Do not modify it directly.
*
* The original plural rule data used for generating this file has the following copyright terms:
*
* Copyright © 1991-2007 Unicode, Inc. All rights reserved.
* Distributed under the Terms of Use in http://www.unicode.org/copyright.html.
*
* @revision $revision (of the original plural file)
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
EOD;
echo "\nreturn " . var_export($allRules, true) . ';';
}
}
......@@ -518,6 +518,7 @@ class YiiBase
* @param string $language the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.
* @return string the translated message
* @see CMessageSource
* @see http://www.unicode.org/cldr/charts/supplemental/language_plural_rules.html
*/
public static function t($message, $params = array(), $language = null)
{
......
......@@ -614,6 +614,12 @@ abstract class Module extends Component
}
if (class_exists($className, false) && is_subclass_of($className, '\yii\base\Controller')) {
$controller = new $className($id, $this);
} elseif (YII_DEBUG) {
if (!class_exists($className, false)) {
throw new InvalidConfigException("Class file name does not match class name: $className.");
} elseif (!is_subclass_of($className, '\yii\base\Controller')) {
throw new InvalidConfigException("Controller class must extend from \\yii\\base\\Controller.");
}
}
}
}
......
......@@ -24,7 +24,6 @@ use yii\base\InvalidRouteException;
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
*
* @since 2.0
*/
class Controller extends \yii\base\Controller
......
......@@ -9,9 +9,9 @@ namespace yii\console\controllers;
use Yii;
use yii\base\Application;
use yii\console\Exception;
use yii\base\InlineAction;
use yii\console\Controller;
use yii\console\Exception;
use yii\console\Request;
use yii\helpers\StringHelper;
......@@ -128,7 +128,7 @@ class HelpController extends Controller
$files = scandir($module->getControllerPath());
foreach ($files as $file) {
if(strcmp(substr($file,-14),'Controller.php') === 0 && is_file($file)) {
if (strcmp(substr($file, -14), 'Controller.php') === 0) {
$commands[] = $prefix . lcfirst(substr(basename($file), 0, -14));
}
}
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE supplementalData SYSTEM "../../common/dtd/ldmlSupplemental.dtd">
<supplementalData>
<version number="$Revision: 6008 $"/>
<generation date="$Date: 2011-07-12 13:18:01 -0500 (Tue, 12 Jul 2011) $"/>
<plurals>
<!-- if locale is known to have no plurals, there are no rules -->
<pluralRules locales="az bm bo dz fa id ig ii hu ja jv ka kde kea km kn ko lo ms my sah ses sg th to tr vi wo yo zh"/>
<pluralRules locales="ar">
<pluralRule count="zero">n is 0</pluralRule>
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="two">n is 2</pluralRule>
<pluralRule count="few">n mod 100 in 3..10</pluralRule>
<pluralRule count="many">n mod 100 in 11..99</pluralRule>
</pluralRules>
<pluralRules locales="asa af bem bez bg bn brx ca cgg chr da de dv ee el en eo es et eu fi fo fur fy gl gsw gu ha haw he is it jmc kaj kcg kk kl ksb ku lb lg mas ml mn mr nah nb nd ne nl nn no nr ny nyn om or pa pap ps pt rof rm rwk saq seh sn so sq ss ssy st sv sw syr ta te teo tig tk tn ts ur wae ve vun xh xog zu">
<pluralRule count="one">n is 1</pluralRule>
</pluralRules>
<pluralRules locales="ak am bh fil tl guw hi ln mg nso ti wa">
<pluralRule count="one">n in 0..1</pluralRule>
</pluralRules>
<pluralRules locales="ff fr kab">
<pluralRule count="one">n within 0..2 and n is not 2</pluralRule>
</pluralRules>
<pluralRules locales="lv">
<pluralRule count="zero">n is 0</pluralRule>
<pluralRule count="one">n mod 10 is 1 and n mod 100 is not 11</pluralRule>
</pluralRules>
<pluralRules locales="iu kw naq se sma smi smj smn sms">
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="two">n is 2</pluralRule>
</pluralRules>
<pluralRules locales="ga"> <!-- http://unicode.org/cldr/trac/ticket/3915 -->
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="two">n is 2</pluralRule>
<pluralRule count="few">n in 3..6</pluralRule>
<pluralRule count="many">n in 7..10</pluralRule>
</pluralRules>
<pluralRules locales="ro mo">
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="few">n is 0 OR n is not 1 AND n mod 100 in 1..19</pluralRule>
</pluralRules>
<pluralRules locales="lt">
<pluralRule count="one">n mod 10 is 1 and n mod 100 not in 11..19</pluralRule>
<pluralRule count="few">n mod 10 in 2..9 and n mod 100 not in 11..19</pluralRule>
</pluralRules>
<pluralRules locales="be bs hr ru sh sr uk">
<pluralRule count="one">n mod 10 is 1 and n mod 100 is not 11</pluralRule>
<pluralRule count="few">n mod 10 in 2..4 and n mod 100 not in 12..14</pluralRule>
<pluralRule count="many">n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14</pluralRule>
<!-- others are fractions -->
</pluralRules>
<pluralRules locales="cs sk">
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="few">n in 2..4</pluralRule>
</pluralRules>
<pluralRules locales="pl">
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="few">n mod 10 in 2..4 and n mod 100 not in 12..14</pluralRule>
<pluralRule count="many">n is not 1 and n mod 10 in 0..1 or n mod 10 in 5..9 or n mod 100 in 12..14</pluralRule>
<!-- others are fractions -->
<!-- and n mod 100 not in 22..24 from Tamplin -->
</pluralRules>
<pluralRules locales="sl">
<pluralRule count="one">n mod 100 is 1</pluralRule>
<pluralRule count="two">n mod 100 is 2</pluralRule>
<pluralRule count="few">n mod 100 in 3..4</pluralRule>
</pluralRules>
<pluralRules locales="mt"> <!-- from Tamplin's data -->
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="few">n is 0 or n mod 100 in 2..10</pluralRule>
<pluralRule count="many">n mod 100 in 11..19</pluralRule>
</pluralRules>
<pluralRules locales="mk"> <!-- from Tamplin's data -->
<pluralRule count="one">n mod 10 is 1 and n is not 11</pluralRule>
</pluralRules>
<pluralRules locales="cy"> <!-- from http://www.saltcymru.org/wordpress/?p=99&lang=en -->
<pluralRule count="zero">n is 0</pluralRule>
<pluralRule count="one">n is 1</pluralRule>
<pluralRule count="two">n is 2</pluralRule>
<pluralRule count="few">n is 3</pluralRule>
<pluralRule count="many">n is 6</pluralRule>
</pluralRules>
<pluralRules locales="lag">
<pluralRule count="zero">n is 0</pluralRule>
<pluralRule count="one">n within 0..2 and n is not 0 and n is not 2</pluralRule>
</pluralRules>
<pluralRules locales="shi">
<pluralRule count="one">n within 0..1</pluralRule>
<pluralRule count="few">n in 2..10</pluralRule>
</pluralRules>
<pluralRules locales="br"> <!-- from http://unicode.org/cldr/trac/ticket/2886 -->
<pluralRule count="one">n mod 10 is 1 and n mod 100 not in 11,71,91</pluralRule>
<pluralRule count="two">n mod 10 is 2 and n mod 100 not in 12,72,92</pluralRule>
<pluralRule count="few">n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99</pluralRule>
<pluralRule count="many">n mod 1000000 is 0 and n is not 0</pluralRule>
</pluralRules>
<pluralRules locales="ksh">
<pluralRule count="zero">n is 0</pluralRule>
<pluralRule count="one">n is 1</pluralRule>
</pluralRules>
<pluralRules locales="tzm">
<pluralRule count="one">n in 0..1 or n in 11..99</pluralRule>
</pluralRules>
<pluralRules locales="gv">
<pluralRule count="one">n mod 10 in 1..2 or n mod 20 is 0</pluralRule>
</pluralRules>
</plurals>
</supplementalData>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment