Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from bushbaby/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
basz committed Nov 13, 2014
2 parents c750ce5 + 67f6ce8 commit 1097a1b
Show file tree
Hide file tree
Showing 40 changed files with 745 additions and 432 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
composer.lock
vendor
8 changes: 8 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tools:
external_code_coverage: true
checks:
php:
code_rating: true
duplication: true
filter:
excluded_paths: [test/*]
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

before_script:
- composer self-update
- composer install --dev --prefer-source
- mkdir -p test/build

script:
- vendor/bin/phpunit -c ./phpunit.xml
- vendor/bin/phpcs --standard=PSR2 ./src/

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover test/build/logs/clover.xml

notifications:
irc: "irc.freenode.org#zftalk.modules"
email: false
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

v1.1.0

- ability to configure orm connection
- configuring of MvcTranslator now done via delegator service
- general refactoring and cleanup
- better unittest
- travis integration
- scrutinzr integration

v1.0.0

- initial release
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Bas Kamer

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
36 changes: 10 additions & 26 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

namespace BsbDoctrineTranslationLoader;

use Zend\I18n\Translator\LoaderPluginManager;
use Zend\ServiceManager\Config;
use Zend\Mvc\MvcEvent;
use Zend\I18n\Translator\Translator;
use BsbDoctrineTranslationLoader\Util\ConfigManipulate;
use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;

class Module
{
public function onBootstrap(MvcEvent $e)
public function init(ModuleManager $moduleManager)
{
$sm = $e->getApplication()->getServiceManager();

/** @var Translator $translator */
$translator = $sm->get('MvcTranslator');

/** @var LoaderPluginManager $plugins */
$plugins = $translator->getPluginManager();
$plugins->setServiceLocator($sm);

/** @var Config $config */
$config = new Config($this->getTranslatorConfig());
$config->configureServiceManager($plugins);
$moduleManager
->getEventManager()
->attach(
ModuleEvent::EVENT_MERGE_CONFIG,
array('BsbDoctrineTranslationLoader\Util\ConfigManipulate', 'onMergeConfig')
);
}

public function getConfig()
Expand All @@ -40,13 +33,4 @@ public function getAutoloaderConfig()
),
);
}

public function getTranslatorConfig()
{
return array(
'factories' => array(
'BsbDoctrineTranslationLoader' => 'BsbDoctrineTranslationLoader\I18n\Translator\Loader\Service\DoctrineFactory',
),
);
}
}
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,39 @@ BsbDoctrineTranslationLoader

BsbDoctrineTranslationLoader is a small ZF2 module that provides a Doctrine based translation loader.

[![Latest Stable Version](https://poser.pugx.org/bushbaby/bsb-doctrine-translation-loader/v/stable.svg)](https://packagist.org/packages/bushbaby/bsb-doctrine-translation-loader) [![Total Downloads](https://poser.pugx.org/bushbaby/bsb-doctrine-translation-loader/downloads.svg)](https://packagist.org/packages/bushbaby/bsb-doctrine-translation-loader) [![Latest Unstable Version](https://poser.pugx.org/bushbaby/bsb-doctrine-translation-loader/v/unstable.svg)](https://packagist.org/packages/bushbaby/bsb-doctrine-translation-loader) [![License](https://poser.pugx.org/bushbaby/bsb-doctrine-translation-loader/license.svg)](https://packagist.org/packages/bushbaby/bsb-doctrine-translation-loader)

[![Build Status](https://travis-ci.org/bushbaby/BsbDoctrineTranslationLoader.svg?branch=master)](https://travis-ci.org/bushbaby/BsbDoctrineTranslationLoader)
[![Code Coverage](https://scrutinizer-ci.com/g/bushbaby/BsbDoctrineTranslationLoader/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/bushbaby/BsbDoctrineTranslationLoader/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bushbaby/BsbDoctrineTranslationLoader/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/bushbaby/BsbDoctrineTranslationLoader/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/bushbaby/BsbDoctrineTranslationLoader/badges/build.png?b=master)](https://scrutinizer-ci.com/g/bushbaby/BsbDoctrineTranslationLoader/build-status/master)
[![Dependency Status](https://www.versioneye.com/user/projects/5464c8ef4de5ef380a000004/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5464c8ef4de5ef380a000004)

## Installation

### as zf2 project
```sh
php composer.phar require "bushbaby/bsb-doctrine-translation-loader:~1.0"
```

Then add `BsbDoctrineTranslationLoader` to the `config/application.config.php` modules list.

BsbDoctrineTranslationLoader works with Composer. To install it into your project, just add the following line into your composer.json file:
Copy the `config/bsb_doctrine_translation_loader.global.php.dist` to the `config/autoload` directory to jump start configuration.

"require": {
"bushbaby/bsb-doctrine-translation-loader": "*"
}

Then update your project by runnning composer.phar update.
Create the required database tables by importing running;

Finally enable the module by adding BsbDoctrineTranslationLoader in your application.config.php file.
mysql database < etc/mysql.sql

### as standalone
## Requirements

For development purposes you might want to install BsbDoctrineTranslationLoader standalone. Clone the project somewhere on your computer
- \>=PHP5.3
- \>=ZF2.2.2

git clone git@github.com:bushbaby/BsbDoctrineTranslationLoader.git BsbDoctrineTranslationLoader
cd BsbDoctrineTranslationLoader
curl -sS https://getcomposer.org/installer | php
git checkout develop
./composer.phar install
phpunit


## Configuration

To configure the module just copy the bsb_doctrine_translation_loader.local.php.dist (you can find this file in the config folder of BsbDoctrineTranslationLoader) into your config/autoload folder, and override what you want.
To configure the module just copy the bsb_doctrine_translation_loader.global.php.dist (you can find this file in the config folder of BsbDoctrineTranslationLoader) into your config/autoload folder, and override what you want.

To enable the loader for a particular text domain add a remote
To enable the loader for a particular text domain add a remote.

```
return array(
Expand All @@ -47,3 +49,16 @@ return array(
);
```

### Change the connection

By default BsbDoctrineTranslationLoader will use the orm_default connection which is configured by DoctrineORMModule. If you need to change the connection, change the 'entity_manager' key;

```
return array(
'bsb_doctrine_translation_loader' => array(
'entity_manager' => 'em_identifier',
),
);
```
Note: that is up to you to [configure](https://github.com/doctrine/DoctrineORMModule/blob/master/docs/configuration.md#how-to-use-two-connections) the DoctrineORMModule such that 'em_identifier' exists as a valid connection.

16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
],
"require": {
"php": ">=5.3.3",

"zendframework/zend-modulemanager" : ">=2.2.2",
"zendframework/zend-i18n": ">=2.2.2",
"zendframework/zend-mvc": ">=2.2.2",
"zendframework/zend-servicemanager": ">=2.2.2",
"zendframework/zend-stdlib": ">=2.2.2",
"zendframework/zendframework": ">=2.2.2",
"doctrine/doctrine-orm-module": ">=0.7"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
"ext-sqlite3" : "~0.7",
"squizlabs/php_codesniffer": "~2.0-RC",
"phpunit/phpunit": "~4.1"
},
"autoload": {
"psr-0": {
"BsbDoctrineTranslationLoader": "src/"
"BsbDoctrineTranslation\\": "src/",
"BsbDoctrineTranslationLoaderTest\\": "test/"
},
"classmap": [
"./Module.php"
"Module.php"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

return array(
'bsb_doctrine_translation_loader' => array(
'entity_manager' => 'orm_default',
),
'translator' => array(
'remote_translation' => array(
/* add a remote translation loader for each text domain */
Expand Down
45 changes: 35 additions & 10 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
<?php

return array(
'doctrine' => array(
'bsb_doctrine_translation_loader' => array(
'entity_manager' => 'orm_default',
/**
* The $config['doctrine'] configuration will be manipulated with these 'template' options
* and will be removed from $config['bsb_doctrine_translator']
*/
'doctrine' => array(
'configuration' => array(
\BsbDoctrineTranslationLoader\Util\ConfigManipulate::EM_REPLACE_TOKEN => array(
'entity_namespaces' => array(
'BsbDoctrineTranslationLoader' => 'BsbDoctrineTranslationLoader\Entity',
),
),
),
'driver' => array(
\BsbDoctrineTranslationLoader\Util\ConfigManipulate::EM_REPLACE_TOKEN => array(
'drivers' => array(
'BsbDoctrineTranslationLoader\Entity' => 'bsbdoctrinetranslationloader_entity',
),
),
),
),
),
'doctrine' => array(
'driver' => array(
'bsbdoctrinetranslationloader_annotation_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src')
'bsbdoctrinetranslationloader_entity' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\XmlDriver',
'paths' => __DIR__ . '/xml/bsbdoctrinetranslationloader',
),
'orm_default' => array(
'drivers' => array(
'BsbDoctrineTranslationLoader\Entity' => 'bsbdoctrinetranslationloader_annotation_driver'
)
)
),
),
'service_manager' => array(
'invokables' => array(
'BsbDoctrineTranslationMvcTranslatorDelegator' => 'BsbDoctrineTranslationLoader\Service\MvcTranslatorDelegatorFactory',
),
'delegators' => array(
'MvcTranslator' => array('BsbDoctrineTranslationMvcTranslatorDelegator'),
),
),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="BsbDoctrineTranslationLoader\Entity\Locale" table="translation_locale">

<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>

<field name="locale" type="string" length="5" nullable="false"/>
<field name="plural_forms" type="string" nullable="false"/>

</entity>

</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="BsbDoctrineTranslationLoader\Entity\Message" table="translation_message">

<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>


<field name="domain" type="string" length="255" nullable="false"/>
<field name="message" type="text" nullable="false"/>
<field name="translation" type="text" nullable="true"/>
<field name="plural_index" type="smallint" nullable="true"/>

<many-to-one field="locale" target-entity="BsbDoctrineTranslationLoader\Entity\Locale" inversed-by="messages">
<join-column name="locale_id" referenced-column-name="id" on-delete="CASCADE" />
</many-to-one>
</entity>

</doctrine-mapping>
39 changes: 39 additions & 0 deletions etc/mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

CREATE TABLE IF NOT EXISTS `translation_locale` (
`id` int(11) NOT NULL,
`locale` varchar(5) NOT NULL,
`plural_forms` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS `translation_message` (
`id` int(11) NOT NULL,
`locale_id` int(11) DEFAULT NULL,
`domain` varchar(255) binary NOT NULL,
`message` longtext NOT NULL,
`translation` longtext,
`plural_index` smallint(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


ALTER TABLE `translation_locale`
ADD PRIMARY KEY (`id`);

ALTER TABLE `translation_message`
ADD PRIMARY KEY (`id`), ADD KEY `IDX_17B1C98DE559DFD1` (`locale_id`);


ALTER TABLE `translation_locale`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5;
ALTER TABLE `translation_message`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=34045;

ALTER TABLE `translation_message`
ADD CONSTRAINT `FK_17B1C98DE559DFD1` FOREIGN KEY (`locale_id`) REFERENCES `translation_locale` (`id`) ON DELETE CASCADE;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Loading

0 comments on commit 1097a1b

Please sign in to comment.