Comments (7)
I don't fully understand your question. Can you elaborate?
from php-po-parser.
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.
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.
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.
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.
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.
No, currently no and I don't think I will add such a method ever, two reasons:
- You can still do what you want with the tools this library offers you (more on this later).
- 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 theEntry
.
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:
- Just call
Catalog::getEntries()
and look what you want in the collection. You will receive an array ofEntry
's that you can traverse and look for the desired entry using any of the methods available inEntry
. - Or implement your own Catalog (just extend
CatalogArray
) and implement a method likegetEntryByMsgStr
. Using this solution do not forget to pass an instance of your own catalog to theParser::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)
- Broken wrapping for multibyte characters HOT 1
- write mo files HOT 3
- Writing plural HOT 2
- So confusing to use HOT 2
- Multiline headers HOT 3
- Write wrapped messages back
- Not correct update Entity in setEntry HOT 1
- Add function getEntryByKey() HOT 5
- How to use CatalogArray to get key and val of all my entries ? HOT 6
- msgfmt fails to convert .po to .mo HOT 5
- unsafe splitting of UTF-8 strings HOT 1
- Call to undefined method Sepia\PoParser\Catalog\CatalogArray::setEntry() HOT 2
- Saving file with escaped qoutes causes excess of backslash characters "\" HOT 4
- Quote is adding on very big string HOT 1
- parseString and parseFile inconsistency HOT 1
- Error on compiling obsolete plurals HOT 3
- Compiler wrapping results in buggy po-file HOT 1
- Parser doesn't remove slashes before quotes HOT 4
- php 7.4 compatibility issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-po-parser.