forum.webdiplomacy.net

webDip dev coordination forum / public access todo list
It is currently Sat Nov 25, 2017 1:50 am

All times are UTC




Post new topic Reply to topic  [ 54 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
PostPosted: Thu Jan 28, 2010 5:35 pm 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
alexintour wrote:
But it's not supported by the official 0.98.
Is that because the developer don't want, or because it's some work to do?
if it's the last option, I'm ready to cooperate and change all the variables in _(variables) in the official release.


I really wish for multi language support too, and jayP did a huge amount of work to integrate gettext into 0.92 but so far there is no official statement from kestasjk about multi language so far.
I really hope, now that the variant-support is done multi language will be next, but for English speaking people multi language support is much lower priority as for the non English speaking.

Oliver


Top
 Profile  
 
PostPosted: Thu Jan 28, 2010 10:36 pm 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
How would people see multi-language being implemented?
To me I think it is very unlikely, possibly even foolhardy, to run a diplomacy website in more than one language. After all, it is a game about communication, and this would be impaired if people did not speak the same language.
However, clearly it would be good for the software to be offered in multiple languages. Putting these together, I just wonder if the best way to do language support is to offer a number of translated versions of webDiplomacy, and let people choose the one they want, rather than making it a soft-coded option.


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 7:09 am 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
figlesquidge wrote:
How would people see multi-language being implemented?

JayP used a really nice solution.
Alls string where quoted with a function named "_()" and they where matched with a translator file during the web-page generation if the language was not set to english.
If the translation had the right quote already it translated the string, if not it returned the English string and made a new line in the translation file so a translator could easy spot what to translante.
Was a matter of 2 hours to translate much of the site to German (did this half a year ago).

Oliver


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 10:24 am 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Wouldn't that have been a massive hit to performance though?


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 11:22 am 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
Not for the English version (no translation needed) and the other is just a stringcompare.
There is not that much to translate, and the full textpages are still in the locale-directory for a hand-translation.
For english text it's:
Code:
        return $token;


For non english text already translated:
Code:
            return $i18n_tokens[$token];

Just not already indexed strings might take a bit to create the diff-file (but it's a one time action)
Not that big performance hit.

The full translation code:
Code:
<?

defined('IN_CODE') or die('This script can not be run by itself.');


/*
 * taken from smarty i18n filter at
 *        http://www.schittkowski.de/index.php?q=node/20
 *
 * Usage:
 *     __("text"); // gettext style
 *
 * print '<p class="notice">End of phase: '.$Game->processTimetxt().'</p>';
 *  -> print '<p class="notice">'. __('End of phase') .': '.$Game->processTimetxt().'</p>';
 *  or
 *  -> printf('<p class="notice">'. __('End of phase: %s') .'</p>', $Game->processTimetxt());
 *
 * above example will automatically add following entry to language file.
 *      $i18n_tokens['End of phase'] = 'End of phase';
 * or   $i18n_tokens['End of phase: %s'] = 'End of phase: %s';
 *
 * You can swap arguments like this
 *   $i18n_tokens['move to %s from %s'] = 'move from %2$s to %1$s'];
 *
 */

if (!Config::$i18n) {
    function __($token, $locale='') {
        return $token;
    }
    function i18n_get_language() {
        return Config::$i18n_default_lang;
    }
    function i18n_prefix() {
        return;
    }
} else {
    function __($token, $locale='') {
        return i18n_substitute_text_token($token, $locale);
    }

    $i18n_tokens = array();
   
    function i18n_get_language() {
        global $User, $i18n_lang;
   
        if (!empty($i18n_lang))
            return $i18n_lang;
        else if (isset($_REQUEST['lang'])) // for testing.
            $lang = $_REQUEST['lang'];
        else if (isset($User->locale) && $User->id != GUESTID) {
            $lang = array_search($User->locale, Config::$i18n_langs);
            if ($lang === FALSE)
                $lang = Config::$i18n_fallback_lang;
        } else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
            $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        else
            $lang = Config::$i18n_fallback_lang;
   
        if (empty($lang))
            $lang = Config::$i18n_default_lang;
        else if (!isset(Config::$i18n_langs[$lang]))
            $lang = Config::$i18n_fallback_lang;

        $i18n_lang = $lang;
        return $lang;
    }

    function i18n_prefix() {
        $lang = i18n_get_language();

        if ($lang == Config::$i18n_default_lang)
            return;
        else
            return $lang.'_';
    }
   
    function i18n_substitute_text_token($token, $locale='') {
        global $i18n_tokens;
   
        // $token = trim($token);
   
        if (isset($i18n_tokens[$token]))
            return $i18n_tokens[$token];
        else {    // token not found, load language file.
            $langdir = './lang';
            if (!empty($locale)) {
                if ($lang = array_search($locale, Config::$i18n_langs))
                    $f = $langdir.'/lang_'.$lang.'.php';
                else
                    $f = $langdir.'/lang_'.Config::$i18n_fallback_lang.'.php';
            } else
                $f = $langdir.'/lang_' . i18n_get_language() . '.php';
   
            if (is_readable($f)) {
                include($f);
                if (isset($i18n_tokens[$token]))
                    return $i18n_tokens[$token];
            } else if (file_exists($f)) { // language file exists but unreadable.
                return $token;
            } else { // lang file does not exist, prepare file with php tag opener
                if (!is_writable($langdir)) {
                    if (file_exists($langdir))
                        return $token;
                    else if (is_writable(dirname($langdir)))
                        mkdir($langdir);
                    else
                        return $token;
                }
                $handle = fopen($f, 'w');
                fwrite($handle, "<?php    // Leave it open!  DO NOT close this with '? >' at the end of file.". PHP_EOL);
                fclose($handle);
            }
        }
   
        // token not found in languages file and file is writable.
        // add token to tokens array for this session & append to file.

        $i18n_tokens[$token] = $token;
   
        if (is_writable($f) && $handle = fopen($f, 'a')) {
            $ts = str_replace("'", "\\'", $token);
            $s = '$i18n_tokens' . "['" . $ts . "']" . " = '" . $ts . "'; // NEW". PHP_EOL;
            fwrite($handle, $s);
            fclose($handle);
        }
   
        return $token;
    }
}

?>


Oliver


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 12:04 pm 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Fair enough, would have to run some tests on it before I could comment more definitively on its efficiencies.
Conceptually that would work fine though yes. Perhaps, if implemented, the variable definition section (ifs at the top of that code that decide whether a language exists or not) could be made such that if the language is set to 'English' the function simply returns the parsed string. That way you don't have to go through the lookup cycle just to find the string is identical.

Are you interested in trialing this on your installation?


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 12:44 pm 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
figlesquidge wrote:
Are you interested in trialing this on your installation?

It's too much work.
JayP did this on his 0.92 installation, but as long as it's not in the main code you have to change soo much code by hand to quote all the strings. And if kestasjk release a new version all the work has to be done again. With all the strings diff-patches won't work.

I prefer a clean installation so it can be updated without a hassle...

Oliver


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 4:34 pm 
Offline

Joined: Thu Jan 14, 2010 7:48 pm
Posts: 87
it's a pity gettext isn't implemented by default.

what if some of us adjust all the _(variables) ? Would it be ok for kestasjk to use the modified 0.98 version in the next releases or not?

It'll be no work for him, and a good compatibility for non english speaking communities.

I'm going to translate the site anyway, but it'll be better if my "work" wasn't only for me... :D


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 5:00 pm 
Offline

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841
alexintour wrote:
it's a pity gettext isn't implemented by default.


Half a year ago JayP did this with V0.92, but it never got into the main distribution.
There were more pressing issues with server load, so the javascript generating order code was implemented first.
With that many new variants finally official variant support was added recently, so the multilanguage-version was pushed back again.

Maybe it could be next on the roadmap, now that all the more pressing changes were made.

I would definatly wait for an official statement from kestasjk, because hiostory has shown (now 2 times) that the amount of time and work is to huge to support that kind of deep changes to the system on a parallel up to date installation.

Maybe kestasjk want to release some more bugfix-releases bevore we can start on a translation.

Oliver


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 6:42 pm 
Offline

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Alex, may I suggest you start with the static files.
They're unlikely to be changed at all so you could just copy them over when you get a new release.
The more actively developed ones (profile/board/forum etc) are likely to change more in the releases so not worth doing, certainly for now.

I would suggest you just hardcode your changes in for now, and when Kestas takes a break from Dev (its his summer break at the moment which I think is why he's had time for it) (( hopefully he'll tell us)) *then* it would be worth translating.
There are a number of other things that could do with being plugged into the game but haven't yet as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 54 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group