pulse00 / Symfony-2-Eclipse-Plugin

Symfony eclipse plugin.
symfony.dubture.com
MIT License
215 stars 48 forks source link

When using database translations, try the cache for the translation files #124

Open xyanide opened 12 years ago

xyanide commented 12 years ago

Currently when using database translations with Symfony2 and this plugin, translations aren`t detected by the plugin as there are no accessible translation files.

When no translation files are available you could revert to the Symfony2 cache translations

/app/cache/dev/translations/

The database translations are cached in this directory and are accessible by symfony.

pulse00 commented 12 years ago

What database translation mechanism do you mean? The only one i am familiar with is using DoctrineExtensions.

Is this the one which caches the translations in cache/dev/translations ?

xyanide commented 12 years ago

To my knowledge they all cache the translations to the /cache/dev/translations directory. This way Symfony knows which translations are available.

In my case i`ve used the following blog article: http://blog.elendev.com/development/php/symfony/use-a-database-as-translation-provider-in-symfony-2/

pulse00 commented 12 years ago

can you post the content of a cached file? i'm not using database translations in any project atm.

xyanide commented 12 years ago

The contents of my catalogue.en.php (cache) file are as following:


<?php

use Symfony\Component\Translation\MessageCatalogue;

$catalogue = new MessageCatalogue('en', array (
  'validators' => 
  array (
    'This value should be false.' => 'This value should be false.',
    'This value should be true.' => 'This value should be true.',
    'This value should be of type {{ type }}.' => 'This value should be of type {{ type }}.',
    'This value should be blank.' => 'This value should be blank.',
    'The value you selected is not a valid choice.' => 'The value you selected is not a valid choice.',
    'You must select at least {{ limit }} choices.' => 'You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.',
    'You must select at most {{ limit }} choices.' => 'You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.',
    'One or more of the given values is invalid.' => 'One or more of the given values is invalid.',
    'The fields {{ fields }} were not expected.' => 'The fields {{ fields }} were not expected.',
    'The fields {{ fields }} are missing.' => 'The fields {{ fields }} are missing.',
    'This value is not a valid date.' => 'This value is not a valid date.',
    'This value is not a valid datetime.' => 'This value is not a valid datetime.',
    'This value is not a valid email address.' => 'This value is not a valid email address.',
    'The file could not be found.' => 'The file could not be found.',
    'The file is not readable.' => 'The file is not readable.',
    'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.' => 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.',
    'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.' => 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.',
    'This value should be {{ limit }} or less.' => 'This value should be {{ limit }} or less.',
    'This value is too long. It should have {{ limit }} characters or less.' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.',
    'This value should be {{ limit }} or more.' => 'This value should be {{ limit }} or more.',
    'This value is too short. It should have {{ limit }} characters or more.' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.',
    'This value should not be blank.' => 'This value should not be blank.',
    'This value should not be null.' => 'This value should not be null.',
    'This value should be null.' => 'This value should be null.',
    'This value is not valid.' => 'This value is not valid.',
    'This value is not a valid time.' => 'This value is not a valid time.',
    'This value is not a valid URL.' => 'This value is not a valid URL.',
    'The two values should be equal.' => 'The two values should be equal.',
    'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.' => 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.',
    'The file is too large.' => 'The file is too large.',
    'The file could not be uploaded.' => 'The file could not be uploaded.',
    'This value should be a valid number.' => 'This value should be a valid number.',
    'This file is not a valid image.' => 'This file is not a valid image.',
    'This is not a valid IP address.' => 'This is not a valid IP address.',
    'This value is not a valid language.' => 'This value is not a valid language.',
    'This value is not a valid locale.' => 'This value is not a valid locale.',
    'This value is not a valid country.' => 'This value is not a valid country.',
    'This value is already used.' => 'This value is already used.',
    'The size of the image could not be detected.' => 'The size of the image could not be detected.',
    'The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.' => 'The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.',
    'The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.' => 'The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.',
    'The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.' => 'The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.',
    'The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.' => 'The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.',
    'This value should be the user current password.' => 'This value should be the user current password.',
    'This value should have exactly {{ limit }} characters.' => 'This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.',
    'The file was only partially uploaded.' => 'The file was only partially uploaded.',
    'No file was uploaded.' => 'No file was uploaded.',
    'No temporary folder was configured in php.ini.' => 'No temporary folder was configured in php.ini.',
    'Cannot write temporary file to disk.' => 'Cannot write temporary file to disk.',
    'A PHP extension caused the upload to fail.' => 'A PHP extension caused the upload to fail.',
    'This collection should contain {{ limit }} elements or more.' => 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.',
    'This collection should contain {{ limit }} elements or less.' => 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.',
    'This collection should contain exactly {{ limit }} elements.' => 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.',
    'This form should not contain extra fields.' => 'This form should not contain extra fields.',
    'The uploaded file was too large. Please try to upload a smaller file.' => 'The uploaded file was too large. Please try to upload a smaller file.',
    'The CSRF token is invalid. Please try to resubmit the form.' => 'The CSRF token is invalid. Please try to resubmit the form.',
  ),
  'messages' => 
  array (
    'addToken' => 'Add token',
    'addLocale' => 'Add language',
    'loginSuccessfull' => 'Welcome %username%, u are successfully logged in!',
    'welcomeUsername' => 'Welcome,. %username%',
  ),
  'breadcrumb' => 
  array (
    'breadcrumbRegister' => 'Register',
  ),
));

return $catalogue;
pulse00 commented 12 years ago

ok, i could simply traverse Symfony\Component\Translation\MessageCatalogue instantiations in the cache/**/translations folder, parse the array passed to the constructor and index the messages like the ones in the regular translations files.

xyanide commented 12 years ago

Yes, that would be great. Could you also show the message catalogue used in that translation? To make it easier to use the requested translation?

pulse00 commented 12 years ago

it's a bit trickier than i though as the cache folder is taken out deliberately from the buildpath during project creation. I can only index stuff that's in the buildpath, but the cache folder has tons of php files which increases build-time a lot and also confuses code-assist, as there's duplicated namespaces and classes in the build-path.

I'll keep you updated if i find a proper solution.

xyanide commented 12 years ago

Isn`t it possible to exclude the cache folder, but include the translations folder during project creation? This way you can access the translations folder but exclude the rest of the cache directories which fixes the build time.

pulse00 commented 12 years ago

yeah, i'll try to find a proper inclusion/exclusion pattern