GithubHelp home page GithubHelp logo

Comments (7)

aleswita avatar aleswita commented on May 20, 2024

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.

TomasHalasz avatar TomasHalasz commented on May 20, 2024

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.

aleswita avatar aleswita commented on May 20, 2024

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.

TomasHalasz avatar TomasHalasz commented on May 20, 2024

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.

aleswita avatar aleswita commented on May 20, 2024

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.

TomasHalasz avatar TomasHalasz commented on May 20, 2024

ok I will send PR. Thanks

from translation.

aleswita avatar aleswita commented on May 20, 2024

@TomasHalasz can you try "space" branch?

from translation.

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.