Comments (7)
If message contain dot and space, translator use message domain by default. Its expected behaviour.
https://github.com/contributte/translation/blob/master/src/Helpers.php#L26
Try this:
$translator->translate('My message with spaces.', null, [], 'my_domain');
from translation.
Thanks but it doesn't help. Tracy said that this translation is missing:
ID: applicationModule.invoice.Forma úhrady:
Domain: messages
Count: 1
It's in form:
protected function createComponentEdit($name)
{
$form = new Form($this, $name);
$form->setTranslator($this->translator);
$this->translator->setPrefix(['applicationModule.invoice']);
$arrPay = $this->PaymentTypesManager->findAll()->order('name')->fetchPairs('id','name');
$form->addSelect('cl_payment_types_id',$this->translator->translate('Forma úhrady:'),$arrPay)
->setTranslator(NULL)
->setHtmlAttribute('class','form-control chzn-select input-sm');
And lang file is applicationModule.cs_CZ.neon:
invoice:
EditDocNum: "upravit číslo dokladu"
Forma úhrady:: "Forma úhrady:"
Result of this in html is: applicationModule.invoice.applicationModule.invoice.Forma úhrady:
The same result I get if I remove: $this->translator->setPrefix(['applicationModule.invoice']);
and use in form: $form->addSelect('cl_payment_types_id',$this->translator->translate('Forma úhrady:', null, [], 'applicationModule.invoice'),$arrPay)
So I don't realy know why is my translation domain ignored....
from translation.
Code bellow works for me:
$translator->setPrefix(['a']);
var_dump($translator->translate('Ahoj jak se mas:', [], 'my_domain'));
a:
Ahoj jak se mas:: "hmm"
from translation.
Ok, and in your example, neon file with translation has name messages.cs_CZ.neon? If yes, it works and its correct. But in my case I need to have translation file named according to domain name.
In next example is translator still looking for translation into messages.cs_CZ.neon:
$translator->setPrefix(['applicationModule.invoice']);
var_dump($translator->translate('Forma úhrady:'));
applicationModule.cs_CZ.neon:
invoice:
Forma úhrady:: "Forma úhrady:"
And I think that reason is in Helpers.php:
public static function extractMessage(string $message): array
{
if (strpos($message, '.') !== false && strpos($message, ' ') === false) {
[$domain, $message] = explode('.', $message, 2);
} else {
$domain = 'messages';
}
return [$domain, $message];
}
Reason is directly in first line with condition. Because exploding string by '.' is done only if $messsage don't contain space.
strpos($message, ' ') === false
And in my message is space, so domain is automaticly given
} else {
$domain = 'messages';
}
Is there some reason to have this part of condition ?
strpos($message, ' ') === false
Wouldn't be better only this ?
if (strpos($message, '.') !== false ) {
[$domain, $message] = explode('.', $message, 2);
} else {
$domain = 'messages';
}
Thanks for your help! :-)
from translation.
My code works for every domain name, look on third parameter. If you set domain in parameter, extract message will be skip -> this is solution for you.
But no idea why strpos($message, ' ') === false is used. You can try send PR with solution without BC breaks.
from translation.
ok I will send PR. Thanks
from translation.
@TomasHalasz can you try "space" branch?
from translation.
Related Issues (20)
- Always shows Czech translation even on `/en/` version of the site HOT 5
- Not working parameters in untranslated message HOT 5
- Latte 3 support HOT 3
- Possibility to change format of translation key HOT 2
- Wrong DB table example? HOT 2
- Nette/Utils 4.0.0 dependency HOT 3
- Locale cannot be changed during request? HOT 2
- "Live" config instead of Neon?
- how to use it on forms HOT 1
- <button> element in forms is not translated properly
- neon loader does not work until specified in translation.loaders
- How to disable translate not existing translations? HOT 5
- BC breaks in the 0.9 branch HOT 4
- Translating doesnt work with symfony/translation v5.3.4 (v5.3.3 is OK) HOT 8
- PrefixedTranslator not working in forms after update to 0.9.x HOT 8
- Unsupported returnOriginalMessage HOT 1
- 1.0.0 release, but tag says 0.9.4 HOT 1
- No loader is registered for the "array" format HOT 3
- Translator returns untranslated message even though the translation exists HOT 2
- BUG - symfony / translation set default locale HOT 1
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 translation.