Code Monkey home page Code Monkey logo

cakephp-i18n's People

Contributors

admad avatar jd-robbs avatar joshwyrick avatar romainbu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp-i18n's Issues

Extract task warns about Invalid marker content

Having gettext handle DB provided content, extract shell task newly warns about Invalid marker content, either silently or with --marker-error verbosely, something that in 3.x was not warned about, is it possible to suppress the 'errors' completely or do I have to live with the notice marker error(s) detected. => Use the --marker-error option to display errors. from now on?
Thank you

# ./bin/cake admad/i18n extract --paths 'src/' --exclude 'src/Controller/Admin/' --exclude 'templates/Admin/' --extract-core no --merge no --languages en_US,fr_FR -v --marker-error
Processing /var/www/app.domain.com/src/Controller/Component/AppComponent.php...                                                                                                     
Invalid marker content in /var/www/app.domain.com/src/Controller/Component/AppComponent.php:257                                                                                     
* __(                                                                                                                                                                                          
$entity->label)

Redirect to default language

I've done this quite ugly solution, to tackle RouteMissingException on URLs that did not contain correct language

// src/Middleware/LanguageRedirectMiddleware.php
<?php

namespace App\Middleware;

use Cake\Core\Configure;
use Cake\Core\InstanceConfigTrait;
use Cake\Http\ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\RedirectResponse;

class LanguageRedirectMiddleware
{
    use InstanceConfigTrait;

    public function __construct($config = [])
    {
    }

    public function __invoke(ServerRequest $request, ResponseInterface $response, $next)
    {
        $langs = Configure::read('I18n.languages');
        $segments = explode('/', $request->getRequestTarget());
        $segment = $segments[1];
        if (!in_array($segment, $langs)) {
            $response = new RedirectResponse(
                '/' . $langs[0] . $request->getRequestTarget(),
                302
            );
            return $response;
        }
        return $next($request, $response);
    }
}

And registering the middleware before routing middleware and error handler

// src/Application.php
    public function middleware($middlewareQueue)
    {
        $middlewareQueue
            ->add(new AssetMiddleware())
            ->add(LanguageRedirectMiddleware::class)
            ->add(ErrorHandlerMiddleware::class)
            ->add(new RoutingMiddleware($this, '_cake_routes_'));
    }

I'd expect cakephp-i18n to redirect to default language route, if the lang param is not present, and i did not find any nicer solution. So just sharing fyi and maybe for inspiration for others.

Also currently it does not redirect to default language, but the first language in I18n.languages configure key

Argument 2 passed to Cake\I18n\TranslatorRegistry::setFallbackPackage()

Hello.

Updated cakephp from 4.1.6 to 4.3.8 using cakephp/upgrade.

Also updated ADmad/cakephp-i18n to 2.2.0.

Added code to config/bootstrap.php

I18n::config('cake', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader($domain, $locale);
});

I18n::config('default', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader($domain, $locale);
});

I18n::config('panel', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader($domain, $locale);
});

I18n::config('frontend', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader($domain, $locale);
});

I18n::config('frontend2', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader($domain, $locale);
});

Now I am getting this error:

Fatal error: [TypeError] Argument 2 passed to Cake\I18n\TranslatorRegistry::setFallbackPackage() must be an instance of Cake\I18n\Package, instance of ADmad\I18n\I18n\DbMessagesLoader given, called in /var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php on line 237 (/var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php:314) #0 /var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php(237): Cake\I18n\TranslatorRegistry->setFallbackPackage('default', Object(ADmad\I18n\I18n\DbMessagesLoader)) #1 /var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php(210): Cake\I18n\TranslatorRegistry->_getTranslator('default', 'en') #2 /var/www/html/vendor/cakephp/cakephp/src/I18n/I18n.php(148): Cake\I18n\TranslatorRegistry->get('default') #3 /var/www/html/vendor/cakephp/cakephp/src/I18n/functions.php(45): Cake\I18n\I18n::getTranslator() #4 /var/www/html/src/View/AppView.php(79): __('Bucheon Univers...') #5 /var/www/html/vendor/cakephp/cakephp/src/View/View.php(350): App\View\AppView->i in /var/www/html/vendor/cakephp/cakephp/src/Error/ErrorHandler.php on line 196

Fatal error: [TypeError] Argument 2 passed to Cake\I18n\TranslatorRegistry::setFallbackPackage() must be an instance of Cake\I18n\Package, instance of ADmad\I18n\I18n\DbMessagesLoader given, called in /var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php on line 237 (/var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php:314) #0 /var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php(237): Cake\I18n\TranslatorRegistry->setFallbackPackage('default', Object(ADmad\I18n\I18n\DbMessagesLoader)) #1 /var/www/html/vendor/cakephp/cakephp/src/I18n/TranslatorRegistry.php(210): Cake\I18n\TranslatorRegistry->_getTranslator('default', 'en') #2 /var/www/html/vendor/cakephp/cakephp/src/I18n/I18n.php(148): Cake\I18n\TranslatorRegistry->get('default') #3 /var/www/html/vendor/cakephp/cakephp/src/I18n/functions.php(45): Cake\I18n\I18n::getTranslator() #4 /var/www/html/src/View/AppView.php(79): __('Bucheon Univers...') #5 /var/www/html/vendor/cakephp/cakephp/src/View/View.php(350): App\View\AppView->i in /var/www/html/vendor/cakephp/cakephp/src/Error/ErrorHandler.php on line 196

Please advise a solution to the problem.

Thank you.

Change default routing language

How to change defualt routing language?
I always get redirected to /en
I tried:

app.php
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'ro_RO'),
Application.php
->add(new \ADmad\I18n\Middleware\I18nMiddleware([
				'defaultLanguage' => 'ro',
				'languages' => [
					'ro' => ['locale' => 'ro_RO'],
					'en' => ['locale' => 'en_US'],
					
				],
			]));
bootstrap.php
Configure::write('I18n.languages', ['ro', 'en']);

When I go to / I get redirected to /en not /ro

My routes

	$routes->connect(
        '/:controller',
        ['action' => 'index'],
        ['routeClass' => 'ADmad/I18n.I18nRoute']
    );
	$routes->connect(
        '/',
		[
			'controller' => 'Pages',
			'action' => 'display','home',
		]);
    $routes->connect(
        '/:controller/:action/*',
        [],
        ['routeClass' => 'ADmad/I18n.I18nRoute']
    );

Handling multi-domain application localization

Hi, is it possible with current state of plugin to have different language route for different domain?

ie. myapp.cz -> lang=cs_CZ, myapp.eu -> lang=en_US

Currently the language is persisted in URL (either as query param or route element), but would be cool, if instead of myapp.cz/cs_CZ/:controller/:action one could omit the cs_CZ/ part and have the language set by current domain of request

View routes get their ID dropped

Hi, we can't get the plugin configured to preserve view action IDs when switching language. Our route connect looks like this:
$routes->connect('/news/view/*', ['controller' => 'News', 'action' => 'view', 'plugin' => 'Blog'], ['routeClass' => 'ADmad/I18n.I18nRoute']);

when we're in a uri /fr/news/view/1 - switching language to english gives us a uri /en/news/view/

The switcher in template looks like this:

<?= $this->Html->link(__('EN'), ['lang' => 'en'], ['class' => $ref_lang == 'en' ? 'lang-btn active' : 'lang-btn']);?>

Any ideas why this can be caused?

Compatibility with cakedc/i18n

Hi,
I've got a mixed environment where I share a table between two projects.

Project A is based on cake 2.x (and cakedc/i18n)
Project B is based on cake 4.x (and cakephp-i18n)

The two projects share table Routes.
My problem is that in 2.x the i18n table stores in field Model the plural: Routes
while in 4.x cakephp-i18n, stores the singular Route

Is there a way to override this behaviour? And store the plural in this plugin? Any idea how I could mantain compatibility?

Thanks
Massimo

Passing arguments for I18n routes seems not working

Maybe i'am doing something totally wrong, but for now i do not see whats wrong with this code.

Works
http://foo.bar/en/main

Works if i omit ['routeClass' => 'ADmad/I18n.I18nRoute']
http://foo.bar/main
http://foo.bar/main/sub/123456

The parameter becomes '123456'

Works not
http://foo.bar/en/main/sub/123456

The parameter stays null.

public function test($id = null) {}

Router::scope('/main', function ($routes) {
        $routes->connect(
            '/',
            [
                'controller'    => 'Pages',
                'action'        => 'index',
            ]
            ,[ 'routeClass' => 'ADmad/I18n.I18nRoute']
        );
        $routes->connect(
            '/sub/:id',
            [
                'controller'    => 'Pages',
                'action'        => 'test',
            ],
            ['routeClass' => 'ADmad/I18n.I18nRoute'],
            [
                'pass'  => [
                    'id',
                ],
                'id' => '[0-9]+'
            ]
        );
    });

Switch language

Hi,

How can I switch between two language and keep the same controller/action with the Url helper or Html helper with your plugin?

Thank you.

Shell task Extract fails to save

I'm not sure what messages and in what format should be present in sources, for Shell ExtractTask to work as intended.

This is with empty DB, config I18n.languages [en,de,fr]

No difference to the error was made by using different configuration of task (core messages y/n, merge into default domain y/n, change sources to only something simple such as app/src/Template/Email)

Exception: SQLSTATE[HY000]: General error: 1364 Field 'value_0' doesn't have a default value in [/var/www/app/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php, line 39]
2019-02-28 07:46:05 Error: [PDOException] SQLSTATE[HY000]: General error: 1364 Field 'value_0' doesn't have a default value in /var/www/app/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php on line 39
Stack Trace:
#0 /var/www/app/vendor/cakephp/cakephp/src/Database/Statement/MysqlStatement.php(39): PDOStatement->execute(NULL)
#1 /var/www/app/vendor/cakephp/cakephp/src/Database/Connection.php(334): Cake\Database\Statement\MysqlStatement->execute()
#2 /var/www/app/vendor/cakephp/cakephp/src/Core/Retry/CommandRetry.php(68): Cake\Database\Connection->Cake\Database\{closure}()
#3 /var/www/app/vendor/cakephp/cakephp/src/Database/Connection.php(337): Cake\Core\Retry\CommandRetry->run(Object(Closure))
#4 /var/www/app/vendor/cakephp/cakephp/src/Database/Query.php(219): Cake\Database\Connection->run(Object(Cake\ORM\Query))
#5 /var/www/app/vendor/cakephp/cakephp/src/ORM/Table.php(2114): Cake\Database\Query->execute()
#6 /var/www/app/vendor/cakephp/cakephp/src/ORM/Table.php(2008): Cake\ORM\Table->_insert(Object(Cake\ORM\Entity), Array)
#7 /var/www/app/vendor/cakephp/cakephp/src/ORM/Table.php(1921): Cake\ORM\Table->_processSave(Object(Cake\ORM\Entity), Object(ArrayObject))
#8 /var/www/app/vendor/cakephp/cakephp/src/ORM/Table.php(1634): Cake\ORM\Table->Cake\ORM\{closure}()
#9 /var/www/app/vendor/cakephp/cakephp/src/Database/Connection.php(738): Cake\ORM\Table->Cake\ORM\{closure}(Object(Cake\Database\Connection))
#10 /var/www/app/vendor/cakephp/cakephp/src/ORM/Table.php(1635): Cake\Database\Connection->transactional(Object(Closure))
#11 /var/www/app/vendor/cakephp/cakephp/src/ORM/Table.php(1922): Cake\ORM\Table->_executeTransaction(Object(Closure), true)
#12 /var/www/app/vendor/admad/cakephp-i18n/src/Shell/Task/ExtractTask.php(255): Cake\ORM\Table->save(Object(Cake\ORM\Entity))
#13 /var/www/app/vendor/admad/cakephp-i18n/src/Shell/Task/ExtractTask.php(214): ADmad\I18n\Shell\Task\ExtractTask->_save('default', 'You don't have ...', NULL, NULL, 'Controller/AppC...')
#14 /var/www/app/vendor/admad/cakephp-i18n/src/Shell/Task/ExtractTask.php(164): ADmad\I18n\Shell\Task\ExtractTask->_write()
#15 /var/www/app/vendor/admad/cakephp-i18n/src/Shell/Task/ExtractTask.php(88): ADmad\I18n\Shell\Task\ExtractTask->_extract()
#16 /var/www/app/vendor/admad/cakephp-i18n/src/Shell/I18nShell.php(38): ADmad\I18n\Shell\Task\ExtractTask->main()
#17 /var/www/app/vendor/cakephp/cakephp/src/Console/Shell.php(532): ADmad\I18n\Shell\I18nShell->main()
#18 /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(371): Cake\Console\Shell->runCommand(Array, true)
#19 /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(166): Cake\Console\CommandRunner->runShell(Object(ADmad\I18n\Shell\I18nShell), Array)
#20 /var/www/app/bin/cake.php(12): Cake\Console\CommandRunner->run(Array)
#21 {main}

sell command(s) isn't compatible with cakephp 4

i get an errors on extracting command with the plugin name
my environment is :
windows 10
php 7.2
cakephp 4.0.4
steps to create the error is try to execute the command
cake ADmad/I18n.i18n extract
bin/cake ADmad/I18n.i18n extract
i'm getting the following error

`C:\Users\ElSngab\Desktop\cakeapp\base\bin>cake admad/i18n.i18n extract
Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Warning Error: preg_match(): Unknown modifier '1'
In [C:\Users\ElSngab\Desktop\cakeapp\base\vendor\cakephp\cakephp\src\Console\Exception\MissingOptionException.php, line 97]

Unknown command cake admad/i18n.i18n. Run cake --help to get the list of commands.
`

and when i change the DS to \ i get none existing command

Unknown command cake admad\i18n.i18n. Run cake --help to get the list of commands.

and when i run cake --help i dont get the command in the list also i can find the commands from other plugin such as BootstrapUI

please note that i had a successfully implement this plugin on older version of cake 3 and the project was going fine but when i did this new project on cake 4 i get this errors

many thanks in advance for your time and effort

Routing prefix

Related to #34, i'm having '/' scope with only custom defined routes (no dashed/inflected/... routes), that works well with the plugin

However I also have '/admin' scope that has DashedRoute as default, because admin controllers are allowed to be dynamic.

Is it possible to have one prefix/scope handled by i18n middleware, and other not?

Weird behavior with i18n routes when no lang is specified

Since I migrate to Cakephp 3.5, I have a strange behavior with the routes.

I have a routes like this in config/routes.php:
$routes->connect( '/blog/:id-:slug', ['controller' => 'Posts', 'action' => 'show'], ['id' => '\d+', 'slug' => '[0-9A-Za-z\-]+', 'pass' => ['id', 'slug'], '_name' => 'blog_show', 'routeClass' => 'ADmad/I18n.I18nRoute'] );

When I try to generate/build the url, with the id and the slug, I get the error:
[Cake\Routing\Exception\MissingRouteException] A named route was found for "blog_show", but matching failed.

The route is correctly configured and everything works great when I remove the routeClass ADmad/I18n.I18nRoute.

This is how I am used to call my route:
Router::url(['_name' => 'blog_show', 'id' => $this->id, 'slug' => $this->slug])

I found a workaround by adding the lang parameter to the array. So it became:
Router::url(['_name' => 'blog_show', 'id' => $this->id, 'slug' => $this->slug, 'lang' => $this->lang])

I think the way how Cakephp is matching the routes with the persisted params has changed but I don't know much about that.

Thank you for your help

How to set I18n route with prefix ?

Hello,

I don't undestand how to do I18n Route when i have a prefix

When i try this

 Router::prefix('opn', function ($routes) {
        $routes->fallbacks(\ADmad\I18n\Routing\Route\I18nRoute::class);
    });

I've got Url like this ---> http://xxx.com/fr/opn/users/token so it's good in my mind
but "Opn" is consider as a controller and not as prefix.

Same issue if i do stuff like this :

 Router::prefix('opn', function ($routes) {
        $routes->connect(
            '/:controller',
            ['action' => 'index'],
            ['routeClass' => 'ADmad/I18n.I18nRoute']
        );
        $routes->connect(
            '/:controller/:action/*',
            [],
            ['routeClass' => 'ADmad/I18n.I18nRoute']
        );
    });

Could you help me please with this ?

Best Regards,

Configuration for DbMessagesLoader

Hi,

I'm using cake 3.8.4 and I try to cofigure DbMessagesLoader.
I only have a single MVC to try it.
I did the Installation/Usage/DbMessagesLoader part of the documentation (including table creation).

I changed a line in the example :
I18n::setConfig('default', function ($domain, $locale) {
with
I18n::config('default', function ($domain, $locale) {
because I18n::setConfig doesn't exist in 3.8.4

The bootstrap section looks like this :

Cache::setConfig(Configure::consume('Cache'));
ConnectionManager::setConfig(Configure::consume('Datasources'));
TransportFactory::setConfig(Configure::consume('EmailTransport'));
Email::setConfig(Configure::consume('Email'));
Log::setConfig(Configure::consume('Log'));
Security::setSalt(Configure::consume('Security.salt'));

// Configure I18n to use DbMessagesLoader for default domain. You need to do
// this for each domain separately.
I18n::config('default', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader(
        $domain,
        $locale
    );
});

When I run the script bin/cake ADmad/I18n.i18n extract, the CLI seems right, but the table "i18n_messages" is not populated.

What did I miss ? Does it still work with cake 3.8.x ?

Custom Redirects

Hey there,

after activating this plugin i seem to have trouble connecting custom routes - specifically a route not following the /:controller/:action convention.

for example i use:
$routes->connect('/mycompany', ['controller' => 'Companies',"action"=>"view"],['routeClass' => 'ADmad/I18n.I18nRoute']);

CakePHP then generates the currect URL:
$this->Url->build(["controller"=>"companies","action"=>"view"]) results in https://myserver.com/en/mycompany
However, when visiting the link, an error occurs:
Error: MycompanyController could not be found.

Do I have to pass a special parameter anywhere?

thanks in advance!

Docs for newer version of CakePHP

Hi, some suggestions regarding the docs when plugin used with recent version of CakePHP

no.1

Plugin::load('ADmad/I18n');

replace with

// in src/Application.php
class Application extends BaseApplication
{
    /**
     * {@inheritDoc}
     */
    public function bootstrap()
    {
        parent::bootstrap();

        $this->addPlugin('ADmad/I18n');
    }
}

no.2
DbMessagesLoader must be placed in bootstrap.php after configuring Cache, ie like this

Cache::setConfig(Configure::consume('Cache'));

I18n::config('default', function ($domain, $locale) {
    return new \ADmad\I18n\I18n\DbMessagesLoader(
        $domain,
        $locale
    );
});

otherwise exception is thrown like this

PHP Fatal error:  Uncaught InvalidArgumentException: The "_cake_core_" cache configuration does not exist. in /var/www/app/vendor/cakephp/cakephp/src/Cache/Cache.php:164
Stack trace:
#0 /var/www/app/vendor/cakephp/cakephp/src/Cache/Cache.php(234): Cake\Cache\Cache::_buildEngine('_cake_core_')
#1 /var/www/app/vendor/cakephp/cakephp/src/I18n/I18n.php(79): Cake\Cache\Cache::engine('_cake_core_')
#2 /var/www/app/vendor/cakephp/cakephp/src/I18n/I18n.php(264): Cake\I18n\I18n::translators()
#3 /var/www/app/config/bootstrap.php(79): Cake\I18n\I18n::config('default', Object(Closure))
#4 /var/www/app/vendor/cakephp/cakephp/src/Http/BaseApplication.php(152): require_once('/var/www/certif...')
#5 /var/www/app/src/Application.php(42): Cake\Http\BaseApplication->bootstrap()
#6 /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(193): App\Application->bootstrap()
#7 /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(136): Cake\Console\CommandRunner->bootstrap()
#8 /var in /var/www/app/vendor/cakephp/cakephp/src/Cache/Cache.php on line 164

Fatal error: Uncaught InvalidArgumentException: The "_cake_core_" cache configuration does not exist. in /var/www/app/vendor/cakephp/cakephp/src/Cache/Cache.php:164
Stack trace:
#0 /var/www/app/vendor/cakephp/cakephp/src/Cache/Cache.php(234): Cake\Cache\Cache::_buildEngine('_cake_core_')
#1 /var/www/app/vendor/cakephp/cakephp/src/I18n/I18n.php(79): Cake\Cache\Cache::engine('_cake_core_')
#2 /var/www/app/vendor/cakephp/cakephp/src/I18n/I18n.php(264): Cake\I18n\I18n::translators()
#3 /var/www/app/config/bootstrap.php(79): Cake\I18n\I18n::config('default', Object(Closure))
#4 /var/www/app/vendor/cakephp/cakephp/src/Http/BaseApplication.php(152): require_once('/var/www/certif...')
#5 /var/www/app/src/Application.php(42): Cake\Http\BaseApplication->bootstrap()
#6 /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(193): App\Application->bootstrap()
#7 /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php(136): Cake\Console\CommandRunner->bootstrap()
#8 /var in /var/www/app/vendor/cakephp/cakephp/src/Cache/Cache.php on line 164

no.3

Launching the shell is not documented now, it could be as simple as

Launch ADmad/I18n.I18n shell

bin/cake a_dmad/i18n.i18n
// or
bin/cake ADmad/I18n.i18n

Default route missing

Currently with this peace of code

Router::defaultRouteClass(I18nRoute::class);

$routerCallbacks = function (RouteBuilder $routes) {
    $routes->setRouteClass(I18nRoute::class);

    $routes->connect('/', ['controller' => 'Public', 'action' => 'home'], ['routeClass' => DashedRoute::class]);
    $routes->connect('/', ['controller' => 'Public', 'action' => 'home']);
};

Router::scope('/', $routerCallbacks);

Routing the default slash route works, without the first route with explicit different routeClass, '/' route always throws NotFoundException (Error: A route matching "/" could not be found.)

Is documentation lacking, or should I18nMiddleware create default route to redirect to correct/default language, and it's not happening with me?

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.