Jump to content

Multi-language page names / URLs


ryan

Recommended Posts

Thanks again for the heads-up. I thought I had removed / disabled all old modules that were in place when I started out.

I definitely do want to use the newer method with LanguageSupportPageNames. Guess I have to play Sherlock Holmes now and take another look if there's anything left that interferes with the latest LSPN method.

Question then: With LanguageSupportPageNames, is it still necessary to enable URL-segments for each template? Or is that also obsolete now? Perhaps that's causing all the issues I'm encountering? (we don't have any pagination, so that's no issue)

Link to comment
Share on other sites

Question then: With LanguageSupportPageNames, is it still necessary to enable URL-segments for each template?

Or is that also obsolete now? Perhaps that's causing all the issues I'm

encountering? (we don't have any pagination, so that's no issue)

No it's not. Unless you need urlSegments for other purposes.

I suggest to make another installation with Pw dev to test out the new language modules/features. It's very logical and simple.

Basically the module allows you to have different names for all your configured languages per page.

  • Like 1
Link to comment
Share on other sites

Wow, you guys are truly great. Thanks for your patience. It's all solved now. I can't believe how easy it all is now. I was basically starting with an older technique, switched to the new one, and there was still all kinds of legacy code here and there. Strange redirects, 404s etc.

Remember that I owe you a beer if you should ever come to this neck of the woods...  ^-^

  • Like 1
Link to comment
Share on other sites

Feature request:

When creating a link in TinyMce in a language other than default, ProcessPageEditLink generates the url of the default language, not the "local" one.

Would be nice if ProcessPageEditLink inserts the url based on the language of the field one is creating the link.

I guess this could be a tricky one...

  • Like 2
Link to comment
Share on other sites

That's an excellent suggestion. I'm honestly not yet sure how to implement it though. I've gone ahead and added a "data-language" attribute, with the language ID, to the LanguageSupport wrapper that goes around each multi-language field. The next step is to get the TinyMCE and CKEditor pwlink.js plugins to pull the language ID from the wrapper–this is the part I can't figure out yet. Once we've got that, the TinyMCE/CKEditor plugins can easily bundle it into the iframe/model request URL as a GET variable. Then the ProcessPageEditLink.module can detect and use it from there. 

  • Like 2
Link to comment
Share on other sites

Nice, thanks ryan :)

Another thing i noticed thought I don't know if intended this way: If I output the name of a page when another language than the default ist set, the name of the default language gets returned.

Example:

// Language is german, name of the page is artikel in german
echo $page->name; // Returns articles (default language), not artikel
Link to comment
Share on other sites

What you are looking for is probably $page->localName($user->language). The LanguageSupportPageNames module modifies the output of $page->path() / $page->url(), but not $page->name. That's because it's kind of a primary identifier for a page that needs to stay consistent at runtime regardless of language.

  • Like 1
Link to comment
Share on other sites

Just implemented this on the site I am doing and I have to say that this is just pure awesomeness! Exactly the way I want things to work when it comes to languages. Thanks, Ryan, for understanding and paying attention to the importance of multi-language support for us poor souls that are not from English speaking nations. 

I do have one problem though that I wanted to ask the forum about. I have this loaded in my main.js to get the pin I want on my google map:

var infoWindow = new google.maps.InfoWindow();
        var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
       var image = {
	   url: '../site/assets/files/1206/pin.png',
	   size: new google.maps.Size(64, 75),
	   origin: new google.maps.Point(0,0),
	   anchor: new google.maps.Point(28, 76)
	   }; 
	     var shadow = {
    url: '../site/assets/files/1206/shadow.png',
        size: new google.maps.Size(105, 52),
    origin: new google.maps.Point(0,0),
    anchor: new google.maps.Point(0, 56)
  };

Works great on my default page, but it won't load the pin (the map loads great apart from that) on the second language page. I recon it has to do with the links. Tried some variations but could not get it going (and I have to find some way to make it work on both pages). Any suggestions? 

Link to comment
Share on other sites

Dragan is right, it your relative URLs wouldn't work just because the path may be changing relative to the language. The fix is as simple as using an absolute path rather than a relative one. 

  • Like 1
Link to comment
Share on other sites

I have an additional question about this. There are some things I have to change manually. For instance i have a custom made Swedish php-function to produce the desired date format. On my English page, I need that function to be replaced with a standard English format. How do I make a simple check if the current language is English for instance (to be used in an if statement to decide which date function to use)?

I should perhaps add that it is for use within a function.  

Link to comment
Share on other sites

I have an additional question about this. There are some things I have to change manually. For instance i have a custom made Swedish php-function to produce the desired date format. On my English page, I need that function to be replaced with a standard English format. How do I make a simple check if the current language is English for instance (to be used in an if statement to decide which date function to use)?

I should perhaps add that it is for use within a function.  

The user has the language set.

if($user->language == "en") ...
  • Like 1
Link to comment
Share on other sites

Yea now it works (after correcting my code error)! I had to go with if (wire("user")->language->name and "english" though to get it to act differently between the languages (since i use "english" for my secondary language). 

Thanks a lot again Soma!

Link to comment
Share on other sites

  • 4 weeks later...

That's an excellent suggestion. I'm honestly not yet sure how to implement it though. I've gone ahead and added a "data-language" attribute, with the language ID, to the LanguageSupport wrapper that goes around each multi-language field. The next step is to get the TinyMCE and CKEditor pwlink.js plugins to pull the language ID from the wrapper–this is the part I can't figure out yet. Once we've got that, the TinyMCE/CKEditor plugins can easily bundle it into the iframe/model request URL as a GET variable. Then the ProcessPageEditLink.module can detect and use it from there. 

Ryan, this is a very important feature to complete the language support. I'm currently working on a multilanguage project that will maybe need to have links localized in TinyMCE.

Can I somehow help with this? I'm not sure what you already have done, but will take a look. Any pointer would be greatly appreciated.

Link to comment
Share on other sites

Me again. I glimpsed at what you already done with that "wrapper".

I now got it working for TinyMCE links plugin. So it will create localized urls when selecting from the page tree.

I had to modify a couple files to add a langID option to ProcessPageList and ProcessPageEditLink. Should I just make a pull request with those changes so you can look at and test?

Edit: Pull Request done https://github.com/ryancramerdesign/ProcessWire/pull/241

  • Like 3
Link to comment
Share on other sites

Hello guys,

this thread has already been proven extremely informative. Thank you for that.

I have a quick question and I'm not sure how to approach it using LanguageSupportPageNames, LanguageSupportFields (latest dev version 2.3.4) - or if it's even possible.

Scenario

- Multiple languages (default, de, fr...)

- PW Multi-Language Support (PageNames etc.)

What If I want to create/publish a page only in DE language, and that page should not be available in the default language?

It could also be a case of "slow on the uptake" on my part. So apology in advance ;-).

Any feedback is much appreciated. Thank you!

regards

//symb

Link to comment
Share on other sites

I now got it working for TinyMCE links plugin. So it will create localized urls when selecting from the page tree.

Thanks for the PR Soma!  I will pull this in within the next day or two and make any necessary updates to the CKEditor plugin as well. 

What If I want to create/publish a page only in DE language, and that page should not be available in the default language?

Default language is required. But you could always add your own checkbox field to the page as a toggle to disable it. Your head.inc or _init.php or whatever your common initialization file is could check: 

if($page->disable_default_language && $user->language->isDefault()) throw new Wire404Exception(); 

You'd also have to consider it with navigation generation, perhaps skipping over pages that have the toggle set while in the default language, or adding it to your selectors when querying pages. 

Edit: you could also just choose to not use the default language at all. 

if($user->language->isDefault()) $user->language = $languages->get("en-us"); // or whatever you want your default to be
  • Like 1
Link to comment
Share on other sites

You're welcome. Ryan, you just have to look at what you take from my PR, because I think you modified some of the files at the same time. Also you may have to check if the code really makes sense and maybe something missing an isset() or alike. I just done it real quick and only tested with multilanguage on.

Link to comment
Share on other sites

if($page->disable_default_language && $user->language->isDefault()) throw new Wire404Exception(); 
if($user->language->isDefault()) $user->language = $languages->get("en-us"); // or whatever you want your default to be

Once again - simple and elegant. Thanks, Ryan! Awesome. I guess my mind is still living in a framework/CMS world where everything needs to be constrained and complicated. ProcessWire lets you breathe.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...