diff options
author | tof <> | 2007-08-27 07:16:27 +0000 |
---|---|---|
committer | tof <> | 2007-08-27 07:16:27 +0000 |
commit | 7e884b51284e83b1604c9d029d3845e77e76d802 (patch) | |
tree | 050c205b14adef43b14d8970a13ea4ff4a8a3a1b /demos/blog-tutorial/protected | |
parent | 37508534ac227c4e39ba8e9eb417d559a7bf0f3e (diff) |
Add Internationalization to Blog-Tutorial
Diffstat (limited to 'demos/blog-tutorial/protected')
4 files changed, 76 insertions, 6 deletions
diff --git a/demos/blog-tutorial/protected/application.xml b/demos/blog-tutorial/protected/application.xml index 5eac200b..2b92159f 100644 --- a/demos/blog-tutorial/protected/application.xml +++ b/demos/blog-tutorial/protected/application.xml @@ -2,12 +2,18 @@ <application id="Dummy" Mode="Debug">
<paths>
- <using namespace="Application.common.*" />
- </paths>
-
+ <using namespace="Application.common.*" /> + <using namespace="System.I18N.*" />
+ </paths> + <modules>
+ <module id="globalization" class="Application.common.BlogTutorialGlobalization" Charset="UTF-8"/> + </modules>
<services>
<service id="page" class="TPageService" DefaultPage="Overview">
<pages MasterClass="Application.layout.MainLayout" Theme="PradoSoft" />
</service>
- </services>
+ </services> + <parameters> + <parameter id="languages" value="('en'=>'English', 'fr'=>'Français')" /> + </parameters>
</application>
\ No newline at end of file diff --git a/demos/blog-tutorial/protected/common/BlogTutorialGlobalization.php b/demos/blog-tutorial/protected/common/BlogTutorialGlobalization.php new file mode 100755 index 00000000..70435e34 --- /dev/null +++ b/demos/blog-tutorial/protected/common/BlogTutorialGlobalization.php @@ -0,0 +1,31 @@ +<?php + +class BlogTutorialGlobalization extends TGlobalizationAutoDetect +{ + public function init($xml) + { + parent::init($xml); + $this->Application->OnBeginRequest[] = array($this, 'beginRequest'); + } + + public function beginRequest($sender, $param) + { + if(null == ($culture=$this->Request['lang'])) + { + if(null !== ($cookie=$this->Request->Cookies['lang'])) + $culture = $cookie->getValue(); + } + + if(is_string($culture)) + { + $info = new CultureInfo(); + if($info->validCulture($culture)) + { + $this->setCulture($culture); + $this->Response->Cookies[] = new THttpCookie('lang',$culture); + } + } + } +} + +?>
\ No newline at end of file diff --git a/demos/blog-tutorial/protected/layout/MainLayout.php b/demos/blog-tutorial/protected/layout/MainLayout.php index 253d6c03..4b5890de 100644 --- a/demos/blog-tutorial/protected/layout/MainLayout.php +++ b/demos/blog-tutorial/protected/layout/MainLayout.php @@ -1,7 +1,30 @@ <?php
class MainLayout extends TTemplateControl
-{
+{ + + public function onLoad($param) + { + parent::onLoad($param); + + $this->languages->DataSource = TPropertyValue::ensureArray($this->Application->Parameters['languages']); + $this->languages->dataBind(); + } + + public function languageLinkCreated($sender, $param) + { + $item = $param->Item; + if($item->ItemType == TListItemType::Item || $item->ItemType == TListItemType::AlternatingItem) + { + $params = $this->Request->toArray(); + $params['lang'] = $sender->DataKeys[$item->ItemIndex]; + unset($params[$this->Request->ServiceID]); + $url = $this->Service->ConstructUrl($this->Service->RequestedPagePath, $params); + $item->link->NavigateUrl = $url; + if($this->Application->Globalization->Culture == $params['lang']) + $item->link->CssClass="active"; + } + }
}
?>
\ No newline at end of file diff --git a/demos/blog-tutorial/protected/layout/MainLayout.tpl b/demos/blog-tutorial/protected/layout/MainLayout.tpl index 1ee83bae..f2bc1f96 100644 --- a/demos/blog-tutorial/protected/layout/MainLayout.tpl +++ b/demos/blog-tutorial/protected/layout/MainLayout.tpl @@ -24,7 +24,17 @@ <com:TopicList ID="TopicPanel" />
</td>
<td valign="top">
-
+<com:TRepeater ID="languages" OnItemCreated="languageLinkCreated"> + <prop:HeaderTemplate> + <div class="languages">Available Languages: <ul> + </prop:HeaderTemplate> + <prop:ItemTemplate> + <li><com:THyperLink ID="link" Text=<%# $this->DataItem %> /></li> + </prop:ItemTemplate> + <prop:FooterTemplate> + </ul></div> + </prop:FooterTemplate> +</com:TRepeater>
<div id="content">
<com:TContentPlaceHolder ID="Main" />
</div>
|