<commit_before># KunstmaanTranslatorBundle [![Build Status](https://travis-ci.org/Kunstmaan/KunstmaanTranslatorBundle.png?branch=master)](http://travis-ci.org/Kunstmaan/KunstmaanTranslatorBundle)

A bundle which enables editing translations in the admin interface without need for editing the translations files.
Translations will be stored in a (default) database and retrieved on the most efficient way possible.

![Symfony2 Profiler Example](Resources/doc/sf2_preview.png)

Installation requirements
-------------------------
You should be able to get Symfony >=2.3 up and running before you can install the KunstmaanTranslatorBundle.

Installation instructions
-------------------------
Assuming you have installed composer.phar or composer binary:

``` bash
$ composer require kunstmaan/translator-bundle
```

Add the KunstmaanTranslatorBundle to your AppKernel.php file:

```PHP
new Kunstmaan\Translator\KunstmaanTranslatorBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
```

Add the KunstmaanTranslatorBundle to your routing.yml. Take your own routing into account, it's possible you will need to add the following code prior to your own routing configurations

```PHP
KunstmaanTranslatorBundle:
    resource: "@KunstmaanTranslatorBundle/Resources/config/routing.yml"
    prefix:   /
```

Overwrite the KunstmaanTranslatorBundle config to your needs in config.yml :

```PHP
kuma_translator:
    enabled: true
```

Migrate dev translations to production
------------------------------------------

Use the following command to generate a doctrine migration with all new and updated translations from your current environment.
```
app/console kuma:translator:migrations:diff
```

When you want to include these migrated translations into your (other) environment use the normal doctrine migrate command.
```
app/console doctrine:migrations:migrate
```

Import existing translation files
-------------------------------------
When migrating your current project you can easily import the existing translation files.

Without parameters, all translations, locales from the current `main` project will be included.
If you have already existing translations in the database with the same combination of 'domain', 'keyword', 'locale', non of them will be overwritten

```
app/console kuma:translator:import
```

To force overwrite the existing translations in the stasher:

```
app/console kuma:translator:import --force
```

To import translations from a specific bundle:

```
app/console kuma:translator:import --bundle=superCoolNewApplicationBundle
```

To import only specific locales:
```
app/console kuma:translator:import --locales=nl,fr,de
```

To import translations from the global Resources (app/Resources/translations)
```
app/console kuma:translator:import --globals
```

How does the cache work
-------------------------------------

Translations are stored in a database, but cached (as Symfony2 normally does) when not running in debug mode.

```php
$kernel = new AppKernel('prod', false); // translations are cached an read from this cache
```

```php
$kernel = new AppKernel('dev', true); // translations are always loaded from the stash (slower, more queries)
```

When editing translations in the backend changes aren't immediately visible on your website.
The backend will show a warning message when not newer or updated translations aren't loaded into the cache.
Click on the `Refresh live` button to rebuild the cache.

Clear cache and request status
-------------------------------------

Clear translation cache files, this will trigger a rebuild of the translation cache when visiting a page
```
app/console kuma:translator:cache --flush
```

Request status of the current cache
```
app/console kuma:translator:cache --status
```

Reset translation flags
-------------------------------------
When all translations are up to date, e.g when migrated all develop translations into production. You need to reset all the flags which mark translations as new or updated.
Otherwise already migrated translations will be added into later migrations again (which can cause errors with inserts and unique keys)

```
app/console kuma:translator:flag --reset
```

Lookup keyword/domain of your translations
-------------------------------------------
You probably don't always remember which keyword and/or domain your translations on specific pages are using. To solve this problem you can add an extra GET parameter to your request. Add `?transSource=1` to your url to see all sources of the translated labels.

You instead of "Hello world" you might see `header.hello_world (messages)`. This means:

* keyword is header.hello_world
* domain is messages

Symfony Profiler integration
-----------------------------

The Symfony2 Profiler show the number of translations used on the current request:

![Symfony2 Profiler Example](Resources/doc/sf2_profiler_bar.png)

When you click on this item, you can see all translations used on the current request and a link to add or edit them in the Kunstmaan Admin backend.

![Symfony2 Profiler Example Table](Resources/doc/sf2_profiler_table.png)



Features<commit_msg>Hardlink preview images<commit_after># KunstmaanTranslatorBundle [![Build Status](https://travis-ci.org/Kunstmaan/KunstmaanTranslatorBundle.png?branch=master)](http://travis-ci.org/Kunstmaan/KunstmaanTranslatorBundle)

A bundle which enables editing translations in the admin interface without need for editing the translations files.
Translations will be stored in a (default) database and retrieved on the most efficient way possible.

![Symfony2 Profiler Example](https://github.com/Kunstmaan/KunstmaanTranslatorBundle/raw/master/Resources/doc/sf2_preview.png)

Installation requirements
-------------------------
You should be able to get Symfony >=2.3 up and running before you can install the KunstmaanTranslatorBundle.

Installation instructions
-------------------------
Assuming you have installed composer.phar or composer binary:

``` bash
$ composer require kunstmaan/translator-bundle
```

Add the KunstmaanTranslatorBundle to your AppKernel.php file:

```PHP
new Kunstmaan\Translator\KunstmaanTranslatorBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
```

Add the KunstmaanTranslatorBundle to your routing.yml. Take your own routing into account, it's possible you will need to add the following code prior to your own routing configurations

```PHP
KunstmaanTranslatorBundle:
    resource: "@KunstmaanTranslatorBundle/Resources/config/routing.yml"
    prefix:   /
```

Overwrite the KunstmaanTranslatorBundle config to your needs in config.yml :

```PHP
kuma_translator:
    enabled: true
```

Migrate dev translations to production
------------------------------------------

Use the following command to generate a doctrine migration with all new and updated translations from your current environment.
```
app/console kuma:translator:migrations:diff
```

When you want to include these migrated translations into your (other) environment use the normal doctrine migrate command.
```
app/console doctrine:migrations:migrate
```

Import existing translation files
-------------------------------------
When migrating your current project you can easily import the existing translation files.

Without parameters, all translations, locales from the current `main` project will be included.
If you have already existing translations in the database with the same combination of 'domain', 'keyword', 'locale', non of them will be overwritten

```
app/console kuma:translator:import
```

To force overwrite the existing translations in the stasher:

```
app/console kuma:translator:import --force
```

To import translations from a specific bundle:

```
app/console kuma:translator:import --bundle=superCoolNewApplicationBundle
```

To import only specific locales:
```
app/console kuma:translator:import --locales=nl,fr,de
```

To import translations from the global Resources (app/Resources/translations)
```
app/console kuma:translator:import --globals
```

How does the cache work
-------------------------------------

Translations are stored in a database, but cached (as Symfony2 normally does) when not running in debug mode.

```php
$kernel = new AppKernel('prod', false); // translations are cached an read from this cache
```

```php
$kernel = new AppKernel('dev', true); // translations are always loaded from the stash (slower, more queries)
```

When editing translations in the backend changes aren't immediately visible on your website.
The backend will show a warning message when not newer or updated translations aren't loaded into the cache.
Click on the `Refresh live` button to rebuild the cache.

Clear cache and request status
-------------------------------------

Clear translation cache files, this will trigger a rebuild of the translation cache when visiting a page
```
app/console kuma:translator:cache --flush
```

Request status of the current cache
```
app/console kuma:translator:cache --status
```

Reset translation flags
-------------------------------------
When all translations are up to date, e.g when migrated all develop translations into production. You need to reset all the flags which mark translations as new or updated.
Otherwise already migrated translations will be added into later migrations again (which can cause errors with inserts and unique keys)

```
app/console kuma:translator:flag --reset
```

Lookup keyword/domain of your translations
-------------------------------------------
You probably don't always remember which keyword and/or domain your translations on specific pages are using. To solve this problem you can add an extra GET parameter to your request. Add `?transSource=1` to your url to see all sources of the translated labels.

You instead of "Hello world" you might see `header.hello_world (messages)`. This means:

* keyword is header.hello_world
* domain is messages

Symfony Profiler integration
-----------------------------

The Symfony2 Profiler show the number of translations used on the current request:

![Symfony2 Profiler Example](https://github.com/Kunstmaan/KunstmaanTranslatorBundle/raw/master/Resources/doc/sf2_profiler_bar.png)

When you click on this item, you can see all translations used on the current request and a link to add or edit them in the Kunstmaan Admin backend.

![Symfony2 Profiler Example Table](https://github.com/Kunstmaan/KunstmaanTranslatorBundle/raw/master/Resources/doc/sf2_profiler_table.png)



Features
{'fraction_non_alphanumeric': 0.12576045627376425, 'fraction_numerical': 0.002091254752851711, 'mean_word_length': 3.8106995884773665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236337', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2613, 'n_words': 1147}