Coder Social home page Coder Social logo

translationtoolsbundle's Introduction

TranslationToolsBundle

Tests Coverage Status

Embed Translation dumpers and extractors for PrestaShop eCommerce CMS. Can be also useful if you need to parse Smarty files.

Installation

As usual, there is few steps required to install this bundle:

1 Add this bundle to your project as a composer dependency:

    // composer.json
    {
        // ...
        require: {
            // ...
            "prestashop/translationtools-bundle": "dev-master"
        }
    }

2 Add this bundle to your application kernel:

    // app/AppKernel.php
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new PrestaShop\TranslationToolsBundle\TranslationToolsBundle(),
        );

        return $bundles;
    }

3 How to contribute

This bundle is unit-tested and well covered. You can execute the tests with this command:

$ ./vendor/bin/phpunit

translationtoolsbundle's People

Contributors

aleeks avatar atomiix avatar dependabot[bot] avatar eternoendless avatar jolelievre avatar julienbourdeau avatar matks avatar matthieu-rolland avatar maximebiloe avatar mickaelandrieu avatar mvorisek avatar pierrerambaud avatar progi1984 avatar quetzacoalt91 avatar rgaillard avatar soullivaneuh avatar sowbiba avatar thierrymarianne avatar toutantic avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

translationtoolsbundle's Issues

preg_replace(): No ending delimiter '#' found

on prestashop 1.7 develop branch and windows 10 running on localhost
get following when try to translate a custom theme
ContextErrorException in Configuration.php line 125: Warning: preg_replace(): No ending delimiter '#' found in Configuration.php line 125 at ErrorHandler->handleError('2', 'preg_replace(): No ending delimiter '#' found', 'C:\www\prestashop1_7\vendor\prestashop\translationtools-bundle\Configuration.php', '125', array('path' => 'C:\www\prestashop1_7\themes\B2VRP\modules\ps_contactinfo\nav.tpl', 'realpath' => 'C:\www\prestashop1_7\themes\B2VRP\modules\ps_contactinfo\nav.tpl')) at preg_replace('#^\#', '', 'C:\www\prestashop1_7\themes\B2VRP\modules\ps_contactinfo\nav.tpl') in Configuration.php line 125 at Configuration::getRelativePath('C:\www\prestashop1_7\themes\B2VRP\modules\ps_contactinfo\nav.tpl') in XliffFileDumper.php line 98 at XliffFileDumper->formatCatalogue(object(MessageCatalogue), 'Shop.Theme', array('path' => 'C:\www\prestashop1_7\app/../themes/B2VRP/translations')) in XliffFileDumper.php line 78 at XliffFileDumper->dump(object(MessageCatalogue), array('path' => 'C:\www\prestashop1_7\app/../themes/B2VRP/translations')) in ThemeExtractor.php line 82 at ThemeExtractor->extract(object(Theme), 'fr-FR') in TranslationsController.php line 402 at TranslationsController->synchronizeTheme('B2VRP', 'fr-FR') in TranslationsController.php line 230 at TranslationsController->getTranslationsCatalogue(object(Request)) in TranslationsController.php line 60 at TranslationsController->listAction(object(Request)) at call_user_func_array(array(object(TranslationsController), 'listAction'), array(object(Request))) in bootstrap.php.cache line 3238 at HttpKernel->handleRaw(object(Request), '1') in bootstrap.php.cache line 3197 at HttpKernel->handle(object(Request), '1', false) in bootstrap.php.cache line 3351 at ContainerAwareHttpKernel->handle(object(Request), '1', false) in bootstrap.php.cache line 2536 at Kernel->handle(object(Request), '1', false) in index.php line 86

Increase tests code coverage to detect Twig version incompatibilities

TranslationToolsBundle v4 is not fully compatible with Twig v2 and Twig v3 although the composer.json states so.

It is very bad that our CI did not detect that our set of Composer dependency ranges was not relevant. Our CI on TranslationToolsBundle is too small. We should have a CI that would go full red when we enable a new major version of one of our dependencies.

Function flattenFiles in making problems

Could you please add verification code to verify if locale code is not yet present in filename??

something like this is working form me:

  public static function flattenFiles($files, $outputPath, $locale, $filesystem, $addLocale = true)
    {
        foreach ($files as $file) {
            $flatName = preg_replace('#[\/\\\]#', '', $file->getRelativePath()).$file->getFilename();

            if ($addLocale) {
                if(!in_array($locale, explode('.', $flatName))){
                    $flatName = preg_replace('#\.xlf#', '.'.$locale.'.xlf', $flatName);
                }
            }

            $filesystem->copy($file->getRealpath(), $outputPath.'/'.$flatName);
        }
        return true;
    }

this is about function in this path: /Translation/Extractor/Util/Flattenizer.php
I hope I'm clear in this explanation if not please let me know.

[EPIC] TranslationToolsBundle compatibility with Twig v1, v2 and v3

Thanks to @atomiix and @sowbiba tests, it has been confirmed that TranslationToolsBundle is not fully compatible with Twig v2 and Twig v3 although the composer.json states so.

It also seems that it will be hard to maintain compatibility with the 3 versions of Twig, given breaking changes between v1 and v2 and v3 and v3.

If this is confirmed, we might need to have TranslationToolsBundle v4 compatible with Twig 1, and TranslationToolsBundle v5 compatible with Twig 3 and maybe 2. TranslationToolsBundle v4 would be used in PrestaShop 1.7.x until 1.7.8 and TranslationToolsBundle v5 would be used in more recent PrestaShop versions.

This means we should keep a branch 4.x open to be able to release patch versions of TranslationToolsBundle v4.

TODO

  1. #90
  2. #91
  3. #92
  4. #93

Twig extractor returns the same message over and over in file where it doen't exist

When trying to translate a module, some messages in twig templates are not visible in the BO interface

Debugging the TwigExtractor class, it seems that we have one message which come back in templates where it doesn't belong

See the video

Kazam_screencast_00020.mp4

The message "It looks like we have trouble connecting to Addons. Please refresh the page or check your firewall configuration." belongs to error.html.twig but the extractor found it again in layout-ajax.html.twig and catalog-refresh.html.twig
But this string is not present in these files

On the other hand we have a lot of wordings which are not extracted

Run tests with twig v1 and twig v2

This library is supposed to be compatible with Twig v1, v2 and v3 because the composer.json allow all of them.

However tests are only run with highest version downloadable by Composer, that is Twig v3. So tests are not run with Twig v1 and v2

Use a callback to catch undefined Twig function

Actually, we have to define again all Twig functions available in PrestaShop codebase to empty them.
Else, Twig throws an exception and the parsing fails.

This could be really MORE EFFICIENT to use the defined callback for it: http://twig.sensiolabs.org/doc/recipes.html#defining-undefined-functions-and-filters-on-the-fly

$twig->registerUndefinedFunctionCallback(function ($name) {
    return new Twig_SimpleFunction($name, array($this, 'emptyFunction'));
});

But we need to enable this callback only in context of our own Translation tool.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.