Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
[Opc_trunk] Modified Opc_Translate class to use default configuration…
Browse files Browse the repository at this point in the history
… 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
megawebmaster committed Mar 5, 2010
1 parent a2177f2 commit 76d1f46
Show file tree
Hide file tree
Showing 18 changed files with 500 additions and 149 deletions.
50 changes: 50 additions & 0 deletions docs/input/en/classes.translate.adapter.ini.txt
@@ -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.
5 changes: 5 additions & 0 deletions docs/input/en/classes.translate.adapter.txt
@@ -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.
51 changes: 51 additions & 0 deletions docs/input/en/classes.translate.adapter.xml.txt
@@ -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.
58 changes: 58 additions & 0 deletions docs/input/en/classes.translate.adapter.yaml.txt
@@ -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.
99 changes: 99 additions & 0 deletions docs/input/en/classes.translate.setup.txt
@@ -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.
6 changes: 5 additions & 1 deletion docs/input/en/classes.translate.txt
@@ -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
33 changes: 32 additions & 1 deletion docs/input/en/classes.view-cache.txt
@@ -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.
5 changes: 5 additions & 0 deletions docs/sort_hints.txt
Expand Up @@ -16,6 +16,11 @@ classes.paginator.decorators.range-slider
classes.paginator.decorators.stepping-slider
classes.paginator.opt
classes.translate
classes.translate.setup
classes.translate.adapter
classes.translate.adapter.ini
classes.translate.adapter.xml
classes.translate.adapter.yaml
classes.view-cache
classes.visit
classes.visit-useragent
Expand Down
7 changes: 7 additions & 0 deletions lib/Class.php
Expand Up @@ -34,6 +34,13 @@ class Opc_Class extends Opl_Class
* @var integer
*/
public $expiryTime = 3600;

// Opc_Translate configuration
/**
* Default language.
* @var string
*/
public $defaultLanugage = 'en';

// Opc_Paginator configuration
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/DoctrineModels.php
Expand Up @@ -119,7 +119,7 @@ static public function setGeneratedModelsDirectoryName($dir)
}
else
{
throw new Opc_DoctrineModelsInvalidDirectoryName_Exception();
throw new Opc_DoctrineModels_InvalidDirectoryName_Exception();
}

} // end setGeneratedModelsDirectoryName();
Expand Down

0 comments on commit 76d1f46

Please sign in to comment.