dorsetdigital

Has anyone encountered an issue where multiple instances of the locale get added to the URL when editing a page? I'm suddenly getting pages in the CMS where the URL is shown as http://example.com/en_GB/en_GB/mypage

Conan

I had to go work on another project, so I will do more debugging next week. But in general if I develop a SilverStripe site with only fluent Locales enabled (no domains), then when the site is finished (all pages translated) and deployed to live, I should be able to just add own domains for locales and everything should work as before except now domains are used instead of locale prefix? (for different locales)

@dorsetdigital I forgot about that, thanks for the tip!

Conan

Hello, yes actually I managed to get it working.

I had to override FluentDirectoryExtension.php, because it never changed the locale. so I created my own CustomFluentDirectoryExtension from FluentDirectoryExtension and replaced the following:

  1. protected function getRuleController($existingRule, $localeObj)
  2. {
  3. $controller = isset($existingRule['Controller']) ? $existingRule['Controller'] : $existingRule;
  4. // Decorate Director class to override controllers for a specific locale
  5. $this->owner->extend('updateLocalePageController', $controller, $localeObj);
  6. return $controller;
  7. }
  8.  
  9. with this
  10.  
  11. protected function getRuleController($existingRule, &$localeObj)
  12. {
  13. $controller = isset($existingRule['Controller']) ? $existingRule['Controller'] : $existingRule;
  14. // Decorate Director class to override controllers for a specific locale
  15. $this->owner->extend('updateLocalePageController', $controller, $localeObj);
  16.  
  17. $localeObj = LocaleDomainUtil::getCurrentLocale(); // I determine which locale by looking at the current URL.
  18. $state = FluentState::singleton();
  19. $state->setLocale($localeObj->Locale);
  20.  
  21. return $controller;
  22. }

I am not working on that project anymore but I hope that code will help you in the right direction. I don't think I needed to add anything else.

dorsetdigital

You could probably just do it with a ServerAlias directive in the apache config FWIW... no need for multiple hosts

wmk

any chance to start xdebug and see what's going on? It should work, I guess it's a config issue. Did you flush? Did you validate your configuration yml? Yml is very picky about whitespace

Conan

My site is under development so I don't got any real domains to try with atm, I try to fake the domains locally so I know what to expect when trying to accomplish this live.

WAMP->Apache->httpd-vhosts.conf(Virtualhosts):

  1. <VirtualHost *>
  2. ServerName http://DomainFrenchExample.com
  3. DocumentRoot "c:/wamp64/www/project/"
  4. <Directory "c:/wamp64/www/">
  5. Deny from all
  6. Allow from 127.0.0.1
  7. </Directory>
  8. </VirtualHost>
  9.  
  10. <VirtualHost *>
  11. ServerName http://DomainSwedishExample.com
  12. DocumentRoot "c:/wamp64/www/project/"
  13. <Directory "c:/wamp64/www/">
  14. Deny from all
  15. Allow from 127.0.0.1
  16. </Directory>
  17. </VirtualHost>

My Windows hosts file:

  • 127.0.0.1 http://DomainFrenchExample.com
  • 127.0.0.1 http://DomainSwedishExample.com

With this I am able to browse to my project by going to my custom domains.

wmk

you can have a dev config with your local domains and a live config for the live domains in one file. Does your local webserver reflect the local domains?

Conan

Hello! I am having some problems regarding using domains for different locales in silverstripe-fluent:

  • I have added two domains & locales in the CMS.
  • For each domain I have set different Default locale values
  • I have added SS_FLUENT_FORCE_DOMAIN="true"to my .env file. The language switcher (loop $Locales -> $Link) now correctly links to another domain on the HomePage but the CurrentLocale does not change. Also after switching to domains it breaks all my translated pages, I get [Emergency] Uncaught InvalidArgumentException: Invalid "TractorCow\Fluent\Model\Locale" locale. when trying to view them.

Any idea what I am missing? Everything works as normal if I remove the use of domains and just have different prefixes with the default URL. Also I have setup virtual hosts to create the domains locally, could that affect this?