This repository has been archived by the owner on May 8, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Opc_trunk] Modified Opc_Translate class to use default configuration…
… from Opc_Class [Opc_trunk] Added documentation for Opc_Translate and all adapters available now. [Opc_trunk] Modified Opc_View_Cache - now it is possible to set caching to all Opt_View objects, by setting to Opt_Class
- Loading branch information
1 parent
a2177f2
commit 76d1f46
Showing
18 changed files
with
500 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Title: Opc_Translate_Adapter_Ini | ||
|
||
---- | ||
|
||
Adapter which uses Ini files as source. | ||
|
||
Available options | ||
================= | ||
|
||
Option | Required? | Default value | Description | ||
------------------|-----------|---------------|------------- | ||
`directory` | Yes | null | Directory, where adapter is searching for language files. | ||
`fileExistsCheck` | No | false | File existence checking before loading file state. | ||
|
||
How to set options to adapter? | ||
============================== | ||
|
||
We have 2 ways of setting options to adapter. | ||
|
||
First | ||
----- | ||
|
||
We could use array use it while constructing new object. | ||
|
||
~~~~ | ||
[php] | ||
$options = array('directory' => './langs/', 'fileExistsCheck' => false); // 1 | ||
$adapter = new Opc_Translate_Adapter_Ini($options); // 2 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Our options array. | ||
> 2. Using it while constructing new object. | ||
|
||
Second | ||
------ | ||
|
||
We could use setters for every option. | ||
|
||
~~~~ | ||
[php] | ||
$adapter = new Opc_Translate_Adapter_Ini(); | ||
$adapter->setDirectory('./langs/'); | ||
$adapter->setFileExistsCheck(false); | ||
~~~~ | ||
|
||
As you can see, all setters have exactly the same name as configuration option. | ||
Remember just to set at least all required options. | ||
|
||
It is possible to get states of features just by replacing `set` by `get` in these methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Title: Opc_Translate_Adapter | ||
|
||
---- | ||
|
||
This class is only an interface, which you have to implement when you want to make you own adapter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
Title: Opc_Translate_Adapter_Xml | ||
|
||
---- | ||
|
||
|
||
Adapter which uses XML files as source. | ||
|
||
Available options | ||
================= | ||
|
||
Option | Required? | Default value | Description | ||
------------------|-----------|---------------|------------- | ||
`directory` | Yes | null | Directory, where adapter is searching for language files. | ||
`fileExistsCheck` | No | false | File existence checking before loading file state. | ||
|
||
How to set options to adapter? | ||
============================== | ||
|
||
We have 2 ways of setting options to adapter. | ||
|
||
First | ||
----- | ||
|
||
We could use array use it while constructing new object. | ||
|
||
~~~~ | ||
[php] | ||
$options = array('directory' => './langs/', 'fileExistsCheck' => false); // 1 | ||
$adapter = new Opc_Translate_Adapter_Xml($options); // 2 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Our options array. | ||
> 2. Using it while constructing new object. | ||
|
||
Second | ||
------ | ||
|
||
We could use setters for every option. | ||
|
||
~~~~ | ||
[php] | ||
$adapter = new Opc_Translate_Adapter_Xml(); | ||
$adapter->setDirectory('./langs/'); | ||
$adapter->setFileExistsCheck(false); | ||
~~~~ | ||
|
||
As you can see, all setters have exactly the same name as configuration option. | ||
Remember just to set at least all required options. | ||
|
||
It is possible to get states of features just by replacing `set` by `get` in these methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Title: Opc_Translate_Adapter_Yaml | ||
|
||
---- | ||
|
||
Adapter which uses Yaml files as source. It uses sfYaml component, which is mantained | ||
and created by Symfony and Sensio Labs. | ||
|
||
Available options | ||
================= | ||
|
||
Option | Required? | Default value | Description | ||
------------------|-----------|---------------|------------- | ||
`directory` | Yes | null | Directory, where adapter is searching for language files. | ||
`fileExistsCheck` | No | false | File existence checking before loading file state. | ||
`compileResult` | No | true | State of compiling results to an php array and saving them to file. | ||
|
||
Compiling results **needs** cache directory which should be placed in language files directory, | ||
e.g. we have language directory `./langs/`, so we have to create directory `./langs/cache/`, | ||
where adapter will store all compiled result files. It is *important* to make PHP available to | ||
write to this directory. | ||
|
||
How to set options to adapter? | ||
============================== | ||
|
||
We have 2 ways of setting options to adapter. | ||
|
||
First | ||
----- | ||
|
||
We could use array use it while constructing new object. | ||
|
||
~~~~ | ||
[php] | ||
$options = array('directory' => './langs/', 'compileResult' => false); // 1 | ||
$adapter = new Opc_Translate_Adapter_Yaml($options); // 2 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Our options array. | ||
> 2. Using it while constructing new object. | ||
|
||
Second | ||
------ | ||
|
||
We could use setters for every option. | ||
|
||
~~~~ | ||
[php] | ||
$adapter = new Opc_Translate_Adapter_Yaml(); | ||
$adapter->setDirectory('./langs/'); | ||
$adapter->setFileExistsCheck(false); | ||
$adapter->setCompileResult(true); | ||
~~~~ | ||
|
||
As you can see, all setters have exactly the same name as configuration option. | ||
Remember just to set at least all required options. | ||
|
||
It is possible to get states of features just by replacing `set` by `get` in these methods. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
Title: Basic setup | ||
---- | ||
|
||
In this chapter you will read about using translation interface. | ||
|
||
Basic Setup | ||
=========== | ||
|
||
Firstly you should configure Opl_Loader and create an instance of Opc_Class. | ||
Then we can configure our Opc_Translate. | ||
|
||
~~~~ | ||
[php] | ||
<?php | ||
// code before is setting up Opl_Loader | ||
$tpl = new Opt_Class; // 1 | ||
$adapter = new Opc_Translate_Adapter_Ini(array('directory' => './langs/')); // 2 | ||
$t = new Opc_Translate($adapter); // 3 | ||
$tpl->setTranslationInterface($t); // 4 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. We create Opt_Class object. | ||
> 2. Now we have to create adapter for Opc_Translate, which handles specific file format. | ||
> 3. Here we create Opc_Translate object. It's constructor needs to have default adapter - adapter witch it will use for all operations. | ||
> 4. And at last we registers translation interface to OPT. It is not needed to completly configure translation interface before setting it to template. | ||
|
||
And that's basic configuration. It uses default language - of course English. | ||
|
||
More translation adapters | ||
========================= | ||
|
||
If you need more adapters for your translation - it is possible to set diffrent adapters to diffrent groups of translation. | ||
|
||
As before you need to configure Opl_Loaded by yourself. | ||
|
||
~~~~ | ||
[php] | ||
<?php | ||
// code before | ||
$tpl = new Opt_Class; | ||
$adapter = new Opc_Translate_Adapter_Ini(array('directory' => './langs/')); // 1 | ||
$t = new Opc_Translate($adapter); | ||
$tpl->setTranslationInterface($t); | ||
$t->setGroupAdapter('groupName', new Opc_Translate_Adapter_Yaml(array('directory' => './yaml_langs/')); // 3 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Creating default adapter. | ||
> 2. Creating additional adapter for group 'groupName'. | ||
|
||
As you can see, that additional adapter is completly diffrent (uses other file format and path to language files). | ||
|
||
Setting language | ||
================ | ||
|
||
Setting language is the easiest part of using Opc_Translate. | ||
|
||
~~~~ | ||
[php] | ||
<?php | ||
// code before | ||
$tpl = new Opt_Class; | ||
$adapter = new Opc_Translate_Adapter_Ini(array('directory' => './langs/')); | ||
$t = new Opc_Translate($adapter); | ||
$tpl->setTranslationInterface($t); | ||
$t->setDefaultLanguage('pl'); // 1 | ||
$t->setLanguage('pl'); // 2 | ||
$t->setGroupLanguage('groupName', 'pl'); // 3 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Setting default language. | ||
> 2. Setting language to load - it's loaded immidiately. | ||
> 3. Setting language for specified group - it's loaded immiadiately. | ||
|
||
When you access to inexistent language Opc_Translate will try to look for default language files. | ||
|
||
---- | ||
|
||
Of course you can get language for every group you want just by using: | ||
~~~~ | ||
[php] | ||
<?php | ||
// code before | ||
$t->getDefaultLanguage(); // 1 | ||
$t->getLanguage(); // 2 | ||
$t->getGroupLanguage('groupName'); // 3 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Getting default language. | ||
> 2. Getting main language. | ||
> 3. Getting specified group language. | ||
|
||
Adapters | ||
-------- | ||
|
||
All adapters are described in details in sections destined to them. All options are described in these sections too. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
Title: Opc_Translate | ||
|
||
---- | ||
---- | ||
|
||
This chapter will describe using and all features of Open Power Classes Translate class. | ||
|
||
It is i18n interface for Open Power Template 2, from version 2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
Title: Opc_View_Cache | ||
|
||
---- | ||
---- | ||
|
||
This is simple class to use Open Power Template caching system. Handles `opt:dynamic` instruction. | ||
|
||
Basic setup | ||
=========== | ||
|
||
The most basic setup is just to create an instance of Opc_View_Cache and set it to Opc_Class. | ||
|
||
~~~~ | ||
[php] | ||
$cache = new Opc_View_Cache(array('cacheDir' => './cache/')); // 1 | ||
$tpl = new Opt_Class; // 2 | ||
// ... | ||
$tpl->setCache($cache); // 3 | ||
~~~~ | ||
|
||
> [steps] | ||
> 1. Creating instance of Opc_View_Cache. | ||
> 2. Creating instance of Opt_Class. | ||
> 3. Setting caching system of Opt_Class to use Opc_View_Cache. | ||
|
||
It's important to set **at least** cache directory. | ||
|
||
Available options | ||
================= | ||
|
||
Option | Required? | Default value | Description | ||
-------------|-----------|---------------|------------- | ||
`cacheDir` | Yes | null | Directory, where cache has to store files. | ||
`expiryTime` | No | 1800 | Time of validity of cache files. | ||
`key` | No | null | Additional key to distinguish the same views and other cache files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.