XH 1.6: 2lang installation

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Tata
Posts: 3141
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

XH 1.6: 2lang installation

Post by Tata » Sat Sep 21, 2013 7:43 pm

Installation went without problem. But I can't create the additional language files. Following the hints, nothing happens. No language menu is visible.

The structure is:
root/content/de vith an empty .2lang file added
Last edited by cmb on Tue Sep 24, 2013 9:19 pm, edited 1 time in total.
Reason: moved from http://cmsimpleforum.com/viewtopic.php?f=2&t=6612
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Holger
Site Admin
Posts: 3193
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany
Contact:

Re: CMSimple_XH 1.6 BETA

Post by Holger » Sat Sep 21, 2013 9:09 pm

Tata wrote:But I can't create the additional language files.
Hi Tata,

you need the following structure:

- root
-- de
---- .2lag
---- index.php

AND

- root
-- content
--- de
----- .htaccess
----- content.htm


Maybe the default download for the beta versions should come with a additional language installed?

At this point I'd like to suggest that it might be usefull when the core creates the 2lang-contenfolder with a default content.htm every time when a second language gets installed.
So the user must only copy one folder as it was before.

KR
Holger

svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm

Re: CMSimple_XH 1.6 BETA

Post by svasti » Sat Sep 21, 2013 9:29 pm

Holger wrote:Maybe the default download for the beta versions should come with a additional language installed?
+1

Tata
Posts: 3141
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: CMSimple_XH 1.6 BETA

Post by Tata » Sat Sep 21, 2013 11:09 pm

Well, now it works. I have not fully understand the steps.
I would also suggest to have one more language pre-installed (de?), or simply assigned as 2lang both in root and in the content folder witih a note in README that any additional langiage shall be installed due copying and renaming any 2lang folders both in root and content folder.
The structure then would be (maybe even):
root/
root/2lang-copy-rename/
root/2lang-copy-rename/content/
root/2lang-copy-rename/content/.htaccess
root/2lang-copy-rename/content/content.htm
root/2lang-copy-rename/.2lang
root/2lang-copy-rename/index.php
...
root/content/
root/content/2lang-copy-rename/
root/content/2lang-copy-rename/content/
root/content/2lang-copy-rename/content/.htaccess
root/content/2lang-copy-rename/content/content.htm
root/content/2lang-copy-rename/.2lang
root/content/2lang-copy-rename/index.php
...
root/content/.htaccess
root/content/index.php

Or let it be created automaticaly from admin backend in configuration as an optional feature with a text field:

Create 2lang [put in 2lang code] [OK]
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 13286
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: CMSimple_XH 1.6 BETA

Post by cmb » Sun Sep 22, 2013 11:33 am

Tata wrote:I have not fully understand the steps.
I'll try to explain. The following is the folder structure as delivered:

Code: Select all

2lang/
\_content/
| \_.htaccess
| \_content.htm
\_.2lang
\_index.php
content/
\_.htaccess
\_content.htm
To create a new language, one has to make a copy of 2lang/ and rename the folder to the desired language code (e.g. fr/):

Code: Select all

2lang/
\_content/
| \_.htaccess
| \_content.htm
\_.2lang
\_index.php
content/
\_.htaccess
\_content.htm
fr/
\_content/
| \_.htaccess
| \_content.htm
\_.2lang
\_index.php
Finally one has to move fr/content/ to /content/fr/:

Code: Select all

2lang/
\_content/
| \_.htaccess
| \_content.htm
\_.2lang
\_index.php
content/
\_fr/
| \_.htaccess
| \_content.htm
\_.htaccess
\_content.htm
fr/
\_.2lang
\_index.php
Offering some (semi-)automatic creation of a new content language might be reasonable. However, we could simply stick with the behavior of classic CMSimple with regard to a missing content.htm: simply present a content with only one empty page and additionally give a warning. The current behavior (dying with "Couldn't read content.htm") has been introduced with CMSimple_XH 1.5.8 only, to avoid potential desynchronization with pagedata.php--as this is no issue anymore with CMSimple_XH 1.6, we could revert to the former the behavior. To test it replace function rfc() in cmsimple/functions.php:

Code: Select all

function rfc()
{
    global $c, $cl, $h, $u, $l, $su, $s, $tx, $e, $pth, $pd_router;

    $contents = XH_readContents();
    if ($contents === false) {
        e('missing', 'content', $pth['file']['content']);
        $contents = array(
            array(), array(), array(), array(), array(),
            new XH_PageDataRouter(array(), array(), array(), array())
        );
    }
    list($u, $tooLong, $h, $l, $c, $pd_router) = array_values($contents);
    $duplicate = 0;

    $cl = count($c);
    $s = -1;

    if ($cl == 0) {
        $c[] = '<h1>' . $tx['toc']['newpage'] . '</h1>';
        $h[] = trim(strip_tags($tx['toc']['newpage']));
        $u[] = uenc($h[0]);
        $l[] = 1;
        if ($su == $u[0]) {
            $s = 0;
        }
        $cl = 1;
        $pd_router->new_page();
        return;
    }

    foreach ($tooLong as $i => $tl) {
        if (XH_ADM && $tl) {
            $e .= '<li><b>' . $tx['uri']['toolong'] . '</b>' . tag('br')
                . '<a href="?' . $u[$i] . '">' . $h[$i] . '</a>' . '</li>';
        }
    }

    foreach ($u as $i => $url) {
        if ($su == $u[$i] || $su == urlencode($u[$i])) {
            $s = $i;
        } // get index of selected page

        for ($j = $i + 1; $j < $cl; $j++) {   //check for duplicate "urls"
            if ($u[$j] == $u[$i]) {
                $duplicate++;
                $h[$j] = $tx['toc']['dupl'] . ' ' . $duplicate;
                $u[$j] = uenc($h[$j]);
            }
        }
    }
} 
Holger wrote:Maybe the default download for the beta versions should come with a additional language installed?
Maybe--I'm not sure. That might as well confuse users.
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3193
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany
Contact:

Re: CMSimple_XH 1.6 BETA

Post by Holger » Sun Sep 22, 2013 12:00 pm

cmb wrote:To test it replace function rfc() in cmsimple/functions.php:
Ok, seems to work. But it does not create the new folder. So saving the empty/new page is still impossible.

Holger
Site Admin
Posts: 3193
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany
Contact:

Re: CMSimple_XH 1.6 BETA

Post by Holger » Sun Sep 22, 2013 12:02 pm

cmb wrote:Holger wrote:
Maybe the default download for the beta versions should come with a additional language installed?

Maybe--I'm not sure. That might as well confuse users.
You're right. One has to find out how to get rid of the unused language..
IMO the best should be a semi-automatic solution.

Holger

oldnema
Posts: 265
Joined: Wed Jan 21, 2009 5:15 pm
Location: Czech Republic
Contact:

Re: CMSimple_XH 1.6 BETA

Post by oldnema » Sun Sep 22, 2013 1:33 pm

Holger wrote:IMO the best should be a semi-automatic solution.
Yes, that would be nice! I spent an hour looking for how to create a second language :oops:
Josef
Nobody knows how much time he has left ...
http://oldnema.compsys.cz/en/?Demo_templates

Tata
Posts: 3141
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: CMSimple_XH 1.6 BETA

Post by Tata » Sun Sep 22, 2013 2:17 pm

To remember the procedure I have prepared the installation packet like this. So I understand, what there's do do if needing a 2lang. And here I can imagine that there would be the 2lang/content.htm accessible in backend and saveable under new name (e.g. de.htm) and a function would in this case:
1. create root/de with /content and all necessary files
2. create root/content/de with all necessary files
3. save the edited content into both root/de/content and root/de/content

So maybe one more item under Settings would be fine 2lang setting with:
Insert the code of desired 2lang (files and directories will be created on submit):
[ ? ? ] [ OK ] [ + ] [ - ]
[ ? ? ] [ OK ] [ + ] [ - ]
[ ? ? ] [ OK ] [ + ] [ - ]
[ Submit ]
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 13286
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: CMSimple_XH 1.6 BETA

Post by cmb » Sun Sep 22, 2013 2:33 pm

I'm not sure if the possibility to create a second language from the back-end is the best option. One one hand this could easily fail due to file system permissions; usually I wouldn't set the root folder writable, so creating root/de/ will fail. On the other hand it might obscure where the files are actually stored, and it won't help when upgrading from an earlier CMSimple(_XH) version.

Another alternative based on the modification of rfc() (which I suggested earlier), would be to create the content/LANG/ folder in XH_saveContents() if it doesn't exist. For testing replace XH_saveContents() in cmsimple/functions.php with the following (and replace rfc() with the alternative above):

Code: Select all

function XH_saveContents()
{
    global $c, $pth, $cf, $tx, $pd_router;

    $hot = '<h[1-' . $cf['menu']['levels'] . '][^>]*>';
    $hct = '<\/h[1-' . $cf['menu']['levels'] . ']>';
    $title = utf8_ucfirst($tx['filetype']['content']);
    $cnts = "<html><head><title>$title</title>\n"
        . $pd_router->headAsPHP()
        . '</head><body>' . "\n";
    foreach ($c as $j => $i) {
        preg_match("/(.*?)($hot(.+?)$hct)(.*)/isu", $i, $matches);
        $page = $matches[1] . $matches[2] . PHP_EOL . $pd_router->pageAsPHP($j)
            . $matches[4];
        $cnts .= rmnl($page . "\n");
    }
    $cnts .= '</body></html>';
    if (!file_exists($pth['folder']['content'])) {
        mkdir($pth['folder']['content'], true);
    }
    return XH_writeFile($pth['file']['content'], $cnts) !== false;
} 
So let's assume the user has copied and renamed 2lang/ as usual. In the back-end he is presented a single empty page ("New Page") and a warning that the content file is missing. Nevertheless he is able to edit this page and save it (the folder and the content.htm will be created). If that doesn't work due to permissions, he gets the warning:
Nicht schreibbar Content-Datei
../content/de/content.htm
IMO far from perfect, but not too bad either. At least the user sees the file path to the expected content.htm and is able to create it himself.
Last edited by cmb on Sun Oct 13, 2013 12:21 pm, edited 1 time in total.
Reason: fixed link
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply