Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
hi,
i using couchCMS with this multilang addon: viewtopic.php?f=5&t=10979

situation is:
i have few languages: en, ru, lt

after changing 'K_PRETTY_URLS', to 1 in config.pp i have one template name with fields output using:
Code: Select all
<cms:get "url_<cms:show lc />" />

thats okey, it works, it's super great!!

I have fields value on my url domain.com/language/template (example: slo.loc/en/about) its great too !!

question
now have a question:
how to make this feature: domain.com/language/tempalate_customroute_from_field

example:
slo.loc/en/aboutus - for english,
slo.loc/ru/onas - for russian
slo.loc/lt/apiemus - for lithuanian
... for other pages should be own url after domain/$lang/$own_page


how I understand, in template i need to make


Code: Select all
<cms:template title="template name" routable='1'>
   <cms:each k_supported_langs as='lang' key='lc'>
      <cms:editable name="seo_group" label='SEO' type='group' order='200'>
         <cms:editable name="url_<cms:show lc />" label="URL <cms:show lang />" type='text' group='seo_group' />
      </cms:editable>
   </cms:each>
   <cms:route name='??????' path="<cms:get "url_<cms:show lc />" />" />
</cms:template>

   <cms:match_route debug='1' />
   
   <cms:if k_matched_route="<cms:get "url_<cms:show lc />" />"> ----- ???????
      <h2>This is list_view</h2>
      <cms:get "url_<cms:show lc />" />
   </cms:if>



in admin panel i have this picture:
Image

I didn't have experience with custom route, maybe someone can help me to solve this question?

and I know, after K_PRETTY_URLS changing to 1, i need to visit admin/gen_htaccess.php to copy all text, and paste to /root/.htaccess file..

really, i don't know how to solve this problem using CouchCMS, maybe @KK or @trendoman can help?
Hi Andrej,

I have come to the same problem with custom routes and multi lang.
Basically we need a modded tag cms:route_link to support multi-lang's url rewrite feature.

I wonder though, if you tried a nested_pages template with masquerading? It looks like custom route is not needed in your use case since urls are quite simple.
Anyways we'll come back with a solution soon (few days tops).
Hello,

I am working on building a multi language site using couch cms and this multi lang addon.

I have come to exacly same problem. I need a solution for this as soon as possible.

Cheers
mamutdev
Yes, this is really a problem for me too :roll:
maybe someone have solution ?
It is very advanced and complicated stuff. Basically, you want to start with writing down all possible translations of urls like this:
Code: Select all
<cms:capture into='lc_options' is_json='1'>
{
   "lc_page": {
      "en": "page",
      "ru": "statja"
   },
   "lc_archive": {
      "en": "archive",
      "ru": "arhiv"
   },
   "lc_week": {
      "en": "week",
      "ru": "nedelja"
   },
   "lc_news": {
      "en": "news",
      "ru": "novosti"
   }
}
</cms:capture>


Next, use that list in creating routes. Add routes to index.php in a following fashion:
Code: Select all
<cms:route name='en-news' path="<cms:show lc_options.lc_news.en />{:format}" filters="" >
   <cms:route_constraints
      format = '(\.html)'
   />   
</cms:route>
<cms:route name='ru-news' path="<cms:show lc_options.lc_news.ru />{:format}" filters="" >
   <cms:route_constraints
      format = '(\.html)'
   />   
</cms:route>


Above means that you have a route named "ru-news" with 2 possible paths:
a. ww.example.com/ru/novosti.html
b. ww.example.com/en/novosti.html

Yes, the problem you will meet is that CouchCMS adds lc (ru/en) to url *after* route has been selected. And there is no way at the moment to add language to cms:route's path. This is okay, because route path must be recognized without multi-lang addon as well: ww.example.com/novosti.html should trigger our route ru-news .

A solution to this problem is in redirect. If currently selected k_lang is "ru" and recognized route is en-news, then it means that url is ww.example.com/ru/news.html. Therefore we must choose what to do. When I was solving this question earlier, I could choose to redirect user to /en/news.html, giving priority to what page is requested or to redirect user to /ru/novosti.html, giving priority to what language is requested. At that time I decided to redirect and give priority to language. So If I am on /en/news.html and want to quickly go to /ru/whatever-news-is-called-in-russian.html -> I simply could change language in url and some code should do the heavy lifting of finding the appropriate counterparty.

I found that cms:route's filters is a good way to do such redirect. I did the following:
For en-news, defined a filter filters="enforce-lc=en" >
For ru-news, defined a filter filters="enforce-lc=ru" >

Content of such filter could look similar to following:
Code: Select all
<cms:if arg_1 ne k_lang ><cms:ignore>

      // Follow lc and give it a priority.
      //
      // Sample route design: path "en/news.html" is the same as "ru/novosti.html"
      //
      // Example where request doesn't match the language: path "ru/news.html"
      //
      // Solution: path "ru/news.html" -->please redirect to--> "ru/novosti.html"
   
   </cms:ignore>
   <cms:capture into='my_alt_route' trim='1'><cms:ignore>

      // Try to find a route with requested "lc" ( ru/news (ru-news) -> en/news (en-news) )

      </cms:ignore>
      <cms:php>echo str_replace( "<cms:show arg_1 />", "<cms:show k_lang />", "<cms:show k_matched_route />");</cms:php>
   </cms:capture>
   <cms:set my_alt_route_link = "<cms:route_link name=my_alt_route lc=k_lang />" />
   <cms:if my_alt_route_link && my_alt_route_link ne '#' ><cms:ignore>

         //

      </cms:ignore>
      <cms:redirect url="<cms:route_link name=my_alt_route lc=k_lang />" permanently='1'/>
   <cms:else />
      <cms:abort is_404='1' />
   </cms:if>
</cms:if>


I highly recommend to use cms:dump extensively and rewrite the filter, because I have so many variants of it in my experiments, I don't even remember which one worked. I wish I had a multi-language website with custom routes from some client to fix this once and for all. I am busy with simple but tedious stuff at the moment. If you have such paid task, do the research and post results here.
7 posts Page 1 of 1