Giter Site home page Giter Site logo

Comments (7)

pherrymason avatar pherrymason commented on July 17, 2024

I don't fully understand your question. Can you elaborate?

from php-po-parser.

mickeyze avatar mickeyze commented on July 17, 2024

Well, I made my .po file with following:

source: wordToBeTranslated
entry : translatedWord

However, in my project, I need to have both ways for checking data in .po file (it is complicated to explain why, so I will skip that part). From source to translation and vice versa. Sepia/PoParse version 4 allowed the option to export all sources+translations in a array which was suitable for Hash::combine and other array manipulations. However, with version 5 there is no such option because there is only export to array of Objects where json_encode and json_decode(array, true) returns empty string.

Please, is there a way to support fetching both items (source from translation and translation from soruce) from .po file?

Thanks,
M

from php-po-parser.

pherrymason avatar pherrymason commented on July 17, 2024

What I think you call source is msgId and your entry is msgStr.

Whenever you call $catalog->getEntry('welcome.user') you recieve an Entry object.
Then you can query those parameters with:

$catalog->getEntry('welcome.user');
$msgId = $entry->getMsgId();  
$msgStr = $entry->getMsgStr();

give it a try

from php-po-parser.

mickeyze avatar mickeyze commented on July 17, 2024

That will be nice if I would know what is my MsgID (welcome.user in your example). But if do not, I need to fetch all list of MsgStr, compare it with my string and then ask for MsgStr for defined MsgId.
Any way to enable getMsgIdForMsgStr ?

from php-po-parser.

pherrymason avatar pherrymason commented on July 17, 2024

msgId is your source. In your previous example:
msgId: wordToBeTranslated
msgStr: translatedWord.

See this example:

$msgId = 'wordToBeTranslated';
$catalog->getEntry($msgId);
$msgId2 = $entry->getMsgId();  
$msgStr = $entry->getMsgStr();

// $msgId == $msgId2

If you paste a sample of your .po file I can give you more details

from php-po-parser.

mickeyze avatar mickeyze commented on July 17, 2024

ok, this is fine:
$msgId = 'wordToBeTranslated';
$catalog->getEntry($msgId);

Now, I have:
$msgStr = 'translatedWord';
is there a way to get: $catalog->getMsgId($msgStr);

from php-po-parser.

pherrymason avatar pherrymason commented on July 17, 2024

No, currently no and I don't think I will add such a method ever, two reasons:

  1. You can still do what you want with the tools this library offers you (more on this later).
  2. And basically, because the job of the Catalog is to be able to store a collection of entries and assign a unique identifier to each of them. This unique identifier is, by design in the PO format the content of the msgid. The msgstr cannot be considered unique (see two different msgid having the same text as translation). Is not the job of the catalog to know about the internal structure of the Entry.

I'm not telling you're not approaching properly to your problem, I'm sure you have a reason, but... if you really need to do that, I see two options:

  1. Just call Catalog::getEntries() and look what you want in the collection. You will receive an array of Entry's that you can traverse and look for the desired entry using any of the methods available in Entry.
  2. Or implement your own Catalog (just extend CatalogArray) and implement a method like getEntryByMsgStr. Using this solution do not forget to pass an instance of your own catalog to the Parser::parse method:
     $catalog = new YourCatalog();
     $parser->parse($catalog);

But as I said, is not guaranteed you will get just one Entry so code defensively against that.

from php-po-parser.

Related Issues (20)

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.