Giter Club home page Giter Club logo

gettexttranslator's People

Contributors

martenb avatar salamek avatar

Stargazers

 avatar

Watchers

 avatar  avatar

gettexttranslator's Issues

Multiple instances of Gettext class

In our project we have separated modules and in order to prevent string clashes by merging all files to one instance of Gettext translator by using addFile we are creating instance of Gettext per module.

And this led to production-only bug as each Gettext translator uses the same cache directory-<lang>.

How to reproduce:

$translator = new Gettext($session, $storage, $response);
$translator->addFile($path, 'messages);
$translator->setProductionMode(true);

echo $translator->translate('Foo'); # Translated as "Goo"

$translator2 = new Gettext($session, $storage, $response);
$translator2->addFile($path, 'messages);
$translator2->setProductionMode(true);

echo $translator2->translate('Foo'); # Translated as "Bar", however "Goo" from cache obtainedfa

Considering two solutions:

  1. Providing explicit tag to distinquish each instance (via constructor where the namespace could altered)
  2. Use hash of absolute filepaths to distinquish cache (local update only in loadDictionary).

The first way seems more plausible as it also prevents related issues (for example with new strings in session).

Plural problem

I have encounered weird behaviour of Gettext::translate

Usage:

{_'%d images were uploaded and inserted.', 1}<br >
{_'%d images were uploaded and inserted.', 2}<br >
{_'%d images were uploaded and inserted.', 5}

Template:

msgid "%d images were uploaded and inserted."
msgid_plural "%d images were uploaded and inserted."
msgstr[0] ""
msgstr[1] ""

Translation:

msgid "%d images were uploaded and inserted."
msgid_plural "%d images were uploaded and inserted."
msgstr[0] "%d image was uploaded and inserted."
msgstr[1] "%d images was uploaded and inserted."

What I get:

1 image was uploaded and inserted.
2 image was uploaded and inserted.
5 image was uploaded and inserted.

It seems to me that the translate function is trying to use the argument as a index into translation array instead of clasifying which group it is and then using the group index.

Is that an error, I am using something not supported or the syntax for this usage is weird?

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.