We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19106
    • 1 Posts
    For inspiration. a nice example (I think) is the textpattern MLP-pack. See http://txp-plugins.netcarving.com/plugins/mlp-pack for more info and http://mlp-demo.netcarving.com/en/video for a demo video.
      • 19889
      • 616 Posts
      Quote from: ganeshXL at May 01, 2007, 06:49 AM

      @madmage:
      I also think that somewhere there has been a PHP variable in which there is the language of the page (be this taken from cookie or from session or whatever). And there should be a field "language" in the content db table.

      I solved this quite easily with alias-names.
      Set up 3 languages = 3 folders.
      3 Templates.
      Every page alias has a suffix: -de, -it or -fr (german, italian or french version)

      All you need to do is create a little snippet which checks the current page alias, and auto-links to alternative languages (if there is an equivalent transl. available, otherwise display a msg like "this page is not avaiable in __"). Include that snippet in your template once, and you’re set.

      I realize this is probably not ideal if you have thousands of pages. The CMS would probably become inefficient. But for small to medium-sized sites, it works.

      Maybe a more sophisticated document-search would help, in the manager:
      e.g. "show only documents that end with "-de" + order by modification date DESC"
      with an option to hide all other stuff not meeting these criteria (avoid clutter in the admin page-navigation).

      If you have several translators who need access to the modx manager, you’d want to give each one only access to his/her language files. You can easily create user-groups for that, and mark your documents accordingly.

      would you mind sharing the snippet you’re using - thank you in advance for your help
        • 10449
        • 956 Posts
        I’ve added comments to my original snippet for better understanding. YMMV.


        
        <?php
        
        
        // reset:
        unset($langStrD);
        unset($langStrF);
        unset($langStrI);
        
        
        // get alias of current document:
        $sitenameAlias = $modx->documentObject['alias'];
        $sitenameAliasC = strlen($sitenameAlias);
        $sitenameRawAlias = substr($sitenameAlias, 0, ($sitenameAliasC - 2));
        $sitenameCurrLang = substr($sitenameAlias, ($sitenameAliasC - 2), 2);
        
        
        // construct alias names for all languages:
        $sitenameAliasItaliano = $sitenameRawAlias . "-i";
        $sitenameAliasFranz = $sitenameRawAlias . "-f";
        $sitenameAliasDeutsch = $sitenameRawAlias . "-d";
        
        
        // get german id for current page (language 1):
        $sqlD = "SELECT id AS IDD FROM modx_site_content WHERE alias='$sitenameAliasDeutsch'";
        $resultsD = $modx->db->query($sqlD);
        if(mysql_num_rows($resultsD) > 0) {
        	while ($row = mysql_fetch_array($resultsD)) {
        		extract($row);
        		// if a german translation exists, link to it:
        		$langStrD .= "<a href='?id=$IDD' title='deutsche Sprachversion'>[ D ]</a>  ";
        	}
        } else {
        		// if this page doesn't exist in german, point to the german homepage instead (frontpage, top level)
        		$langStrD .= "<a href=\"http://www.sitename.ch/?id=2\" onclick=\"javascript: return confirm('Deutsche Version dieser Seite existiert nicht. Möchten Sie zur deutschsprachigen Startseite wechseln?');\">[ D ]</a>  ";
        }
        
        
        // get french id for current page (language 2):
        $sqlF = "SELECT id AS IDF FROM modx_site_content WHERE alias='$sitenameAliasFranz'";
        $resultsF = $modx->db->query($sqlF);
        if(mysql_num_rows($resultsF) > 0) {
        	while ($row = mysql_fetch_array($resultsF)) {
        		extract($row);
        		// if a french translation exists, link to it:
        		$langStrF .= "<a href='?id=$IDF' title='français'>[ F ]</a>  ";
        	}
        } else {
        		// if this page doesn't exist in french, point to the french homepage instead (frontpage, top level)
        		$langStrF .= "<a href=\"http://www.sitename.ch/?id=259\" onclick=\"javascript: return confirm('La version française de cette page n\'existe pas. Voulez-vous passer à la page d\'accueil de la version française?');\">[ F ]</a>  ";
        }
        
        
        $sqlI = "SELECT id AS IDI FROM modx_site_content WHERE alias='$sitenameAliasItaliano' ";
        $resultsI = $modx->db->query($sqlI);
        if(mysql_num_rows($resultsI) > 0) {
        	while ($row = mysql_fetch_array($resultsI)) {
        		extract($row);
        		// if an italian translation exists, link to it:
        		$langStrI .= "<a href='?id=$IDI' title='italiano'>[ I ]</a>  ";
        	}
        } else {
        		// if this page doesn't exist in italian, point to the italian homepage instead (frontpage, top level)
        		$langStrI .= "<a href=\"http://www.sitename.ch/?id=377\" onclick=\"javascript: return confirm('La versione italiana di questa pagina non esiste. Desidera cambiare e accedere alla pagina d\'inizio della versione italiana?');\">[ I ]</a>  ";
        }
        
        
        
        // finally, display language switch links:
        // e.g. only display alternative languages
        // if we're on a german page, only display links to french + italian
        // "deep link" to equivalent doc if available
        // or to french/italian frontpage, if that doc is not translated yet
        
        if($sitenameCurrLang == '-d') {
        	echo "$langStrF $langStrI";
        }
        
        if($sitenameCurrLang == '-f') {
        	echo "$langStrD $langStrI";
        }
        
        if($sitenameCurrLang == '-i') {
        	echo "$langStrD $langStrF";
        }
        
        
        
        ?>
        
        
        



        I saved the snippet as langSwitch, and simply inserted [!langSwitch!] into my main site navigation, on top.
        i.e. if you accidentally landed on the french page (e.g. via Google), you can simly choose one of the other available lang. versions.

        Since there’s always a time-lag between publishing the original docs (german) and the translations (italian + french), and the client
        doesn’t want ALL docs translated anyway, the snippet points you to the frontpage in such cases.

        Hope it helps.