Skip to content

Commit

Permalink
Release 1.0.0 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
greeflas authored Apr 22, 2018
1 parent ad05bd8 commit 7aa51fd
Show file tree
Hide file tree
Showing 22 changed files with 1,255 additions and 340 deletions.
43 changes: 43 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
filter:
excluded_paths:
- tests/*
checks:
php:
code_rating: true
duplication: false
unused_methods: true
unused_parameters: true
argument_type_checks: true
verify_property_names: true
method_calls_on_non_object: false
fix_doc_comments: true
instanceof_class_exists: true
catch_class_exists: true
assignment_of_null_return: false
use_statement_alias_conflict: false
simplify_boolean_return: true
return_doc_comments: true
return_doc_comment_if_not_inferrable: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
parameters_in_camelcaps: true
parameter_doc_comments: true
param_doc_comment_if_not_inferrable: true
properties_in_camelcaps: true
no_long_variable_names:
maximum: '27'
no_goto: true
more_specific_types_in_doc_comments: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: false
fix_line_ending: true
fix_php_opening_tag: true

coding_style:
php:
spaces:
around_operators:
concatenation: true
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

# environment variable used in test suite
env: TEST_ENVIRONMENT=travis

# faster builds on new travis setup not using sudo
sudo: false

# cache vendor dirs
cache:
directories:
- vendor
- $HOME/.composer/cache

# install dependencies
install:
- travis_retry composer self-update && composer --version
- travis_retry composer update --prefer-dist --no-interaction

# run tests
script:
- composer validate --no-check-lock
- composer test
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Translatable Behavior Change Log
--------------------------------

1.0.0 Under development
-----------------------
1.0.0 April 22, 2018
--------------------
* Initial release (greeflas)

Development started March 18, 2018
Expand Down
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<p align="center">
<a href="https://github.com/yiimaker" target="_blank">
<img src="https://avatars1.githubusercontent.com/u/24204902" height="100px">
</a>
<h1 align="center">Translatable behavior</h1>
</p>

[![Build Status](https://travis-ci.org/yiimaker/yii2-translatable.svg?branch=master)](https://travis-ci.org/yiimaker/yii2-translatable)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiimaker/yii2-translatable/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiimaker/yii2-translatable/?branch=master)
[![Total Downloads](https://poser.pugx.org/yiimaker/yii2-translatable/downloads)](https://packagist.org/packages/yiimaker/yii2-translatable)
[![Latest Stable Version](https://poser.pugx.org/yiimaker/yii2-translatable/v/stable)](https://packagist.org/packages/yiimaker/yii2-translatable)
[![Latest Unstable Version](https://poser.pugx.org/yiimaker/yii2-translatable/v/unstable)](https://packagist.org/packages/yiimaker/yii2-translatable)

Translatable behavior aggregates logic of linking translations to the primary model.

Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require yiimaker/yii2-translatable
```

or add

```
"yiimaker/yii2-translatable": "~1.0"
```

to the `require` section of your `composer.json`.

Usage
-----

1. Add behavior to the your primary model

```php
public function behaviors()
{
return [
// ...
'translatable' => [
'class' => TranslatableBehavior::className(),
// 'translationRelationName' => 'translations',
// 'translationLanguageAttrName' => 'language',
// 'attributeNamePattern' => '%name% [%language%]',
'translationAttributeList' => [
'title',
'description',
],
],
];
}
```

2. And use `getTranslation()` or `translateTo()` methods

```php
// product is an active record model with translatable behavior
$product = new Product();

// sets translation for default application language
$product->title = 'PhpStrom 2018.1';
$product->description = 'Лицензия PhpStrom IDE версия 2018.1';

// gets translation for English language
$translation = $product->getTranslation('en');
$translation->title = 'PhpStrom 2018.1';
$translation->description = 'License of the PhpStrom IDE version 2018.1';

// sets description for French language
$product->translateTo('fr')->description = 'La licence de PhpStorm IDE la version 2018.1';

$product->insert();
```

`translateTo()` it's just an alias for `getTranslation()` method.

After saving the model you can fetch this model from the database and translatable behavior will fetch all translations automatically.

```php
$product = Product::find()
->where(['id' => 1])
->with('translations')
->one()
;

// gets translation for English language
$product->translateTo('en')->description; // License of the PhpStrom IDE version 2018.1
// gets translation for French language
$product->translateTo('fr')->description; // La licence de PhpStorm IDE la version 2018.1

// check whether Ukrainian translation not exists
if (!$product->hasTranslation('uk')) {
$product->translateTo('uk')->description = 'Ліцензія PhpStrom IDE версія 2018.1';
}

// update Enlish translation
$product->translateTo('en')->title = 'PhpStorm IDE';

$product->update();
```

Tests
-----

You can run tests with composer command

```
$ composer test
```

or using following command

```
$ codecept build && codecept run
```

Contributing
------------

For information about contributing please read [CONTRIBUTING.md](CONTRIBUTING.md).

License
-------

[![License](https://poser.pugx.org/yiimaker/yii2-translatable/license)](https://packagist.org/packages/yiimaker/yii2-translatable)

This project is released under the terms of the BSD-3-Clause [license](LICENSE).

Copyright (c) 2017-2018, Yii Maker
26 changes: 26 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Yii2:
cleanup: false
configFile: 'tests/_config/app.php'
Db:
dsn: 'sqlite:tests/_output/test.db'
user: ''
password: ''
dump: 'tests/_data/dump.sql'
cleanup: true,
populate: true,
reconnect: false
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yiimaker/yii2-translatable",
"description": "",
"description": "Translatable behavior aggregates logic of linking translations to the primary model",
"keywords": ["yii2", "behavior", "translatable", "translation", "translations", "ar"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
Expand Down
Loading

0 comments on commit 7aa51fd

Please sign in to comment.