Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: 1 2 [3] 4

Author Topic: Multi Languages  (Read 24861 times)

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Multi Languages
« Reply #30 on: March 12, 2007, 06:53:59 AM »

I have my take on it working as well... not online yet (I only know the one lang anyway :( )
Am in the process of removing items from the admin of the child snews.php that should be sitewide only.
eg, password change, content controls (leaving display page option), comments controls (leaving badword filter -- will be different for each language).

Results in site that can be multi languaged, where each lang is administered through it's own admin, with all sitewide admin options available only in the parent (root) admin panel. Single password/user/login to backend, with login only required once to access all language sections.

All lang categories and articles are separate from each other.

Parent snews.php changes
adding session var for lang
new function for lang_link generation, called in index.php (may move this to index.php to remove repitition)

Child snews.php changes
stripping unrequired admin bits
filtering settinings function, to use sitewide when required, else lang specific settings.
requires prefix for db access. no other differences in database vars

Extra scripting in index.php. Similar to leo's

Have set up a "setup" script that will generate the new tables. Used in the parent site (included in an article) brings the new lang site online rapidly.
Logged
Of all the things I have lost, it is my mind that I miss the most.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Multi Languages
« Reply #31 on: March 12, 2007, 11:04:34 AM »

ok Leo, had a look at your site...

How did you tie the comment to the same (but translated) article?
Logged
Of all the things I have lost, it is my mind that I miss the most.

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #32 on: March 12, 2007, 11:44:23 AM »

I didn't create a new comments table.

I'm going to write something into my site soon.
In the while, download this file:
http://prosperi.ath.cx/files/language.zip

It' s better that you look at there, it's easier than understand my explanation.
Also I'm waiting for suggestions, critics, and improvements.

Leonardo
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Multi Languages
« Reply #33 on: March 12, 2007, 01:28:38 PM »

Quote from: leo1981
I didn't create a new comments table.

I'm going to write something into my site soon.
In the while, download this file:
http://prosperi.ath.cx/files/language.zip

It' s better that you look at there, it's easier than understand my explanation.
Also I'm open to suggestions and improvement.

Leonardo
Ahhh, that explains that then...
so, you would have to be careful to keep your various article tables in line with each other, in order to get comments being placed on correct translated article.

The only "issue" I might have, is the way you ave renamed snews.php.

If you have a look at the language function, it is looking for a file named the same way as you have named the altered snews.php... although it is redundant search, as you are not altering the site language setting as such.

The more I look at this, the more I am convinced that it would take very little to do all this with just the one snews.php, setting a session var on lang change (as you have [me too]).
Indeed, your altered tables make for a more compact solution, so only need to alter those fields that are to be inserted/updated, which means just need to use the session lang var to access the language articles/categories automatically. That would then enable multiple lang, with only one snews.php plus separate language files (after altering language function) .
Logged
Of all the things I have lost, it is my mind that I miss the most.

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #34 on: March 12, 2007, 02:51:17 PM »

Quote from: philmoz
Ahhh, that explains that then...
so, you would have to be careful to keep your various article tables in line with each other, in order to get comments being placed on correct translated article.
I let comments be in both languages, if you comment an english article, your comment will be also in italian article.

Quote from: philmoz
The only "issue" I might have, is the way you ave renamed snews.php.
It's possible to integrate everything in one file snews.php, e.g. using a pre/postfix for names.
I used "title" for EN and "title_XX" for XX. I can use a variable ($langx)  to call "title_".$langx.

Quote from: philmoz
If you have a look at the language function, it is looking for a file named the same way as you have named the altered snews.php... although it is redundant search, as you are not altering the site language setting as such.
I'm new with PHP, I started to know PHP few days ago, when I thought of change my site.
My choices can be disputable, I know.

Quote from: philmoz
The more I look at this, the more I am convinced that it would take very little to do all this with just the one snews.php, setting a session var on lang change (as you have [me too]).
Indeed, your altered tables make for a more compact solution, so only need to alter those fields that are to be inserted/updated, which means just need to use the session lang var to access the language articles/categories automatically. That would then enable multiple lang, with only one snews.php plus separate language files (after altering language function) .
You are right, it's possible.

I wrote a new mod, with only a main snews.php, and snews_xx.php for the other language settings as before. This time I had to rename something in the db.
For download: http://prosperi.ath.cx/files/language.zip

Leonardo
Logged

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #35 on: March 16, 2007, 08:27:14 PM »

This is the guide I promise:
THIS IS A WIP, PLEASE READ NEXT POSTS

This mod creates a multi contents/settings website with sNews 1.5.

NOTE: I'm considering EN as the default language, and XX as the second.
Please change XX (or _xx) into your language.

1. Setup the database, please use this code carefull, if you modify your DB,  your previous sNews.php won't work anymore. You have to rename some elements of the DB:
Code: [Select]
ALTER TABLE `categories` CHANGE `name` `name_en` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `categories` CHANGE `description` `description_en` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;
ALTER TABLE `articles` CHANGE `text` `text_en` LONGTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
ALTER TABLE `articles` CHANGE `title` `title_en` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;

ALTER TABLE categories ADD name_xx varchar(100) NOT NULL;
ALTER TABLE categories ADD description_xx varchar(255) NOT NULL;
ALTER TABLE articles  ADD title_xx varchar(100) default NULL;
ALTER TABLE articles  ADD text_xx longtext;
2. Add the snews_XX.php file with the site language variables (download from the sNews forum).

3. Substitute the first line of index.php with:

Code: [Select]
if (!isset($_SESSION['langx']) && !$_GET['lang']){
$_SESSION['langx']=substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
}else{
if($_GET['lang'])
$_SESSION['langx']=$_GET['lang'];
}
include('snews.php');
?>
and add a switch command in the file wherever:
Code: [Select]
Xxx - Eng4. Check the included snews.php for changes.
Changes:
Code: [Select]
// LANGUAGE VARIABLES
function l($variable) {
                if (file_exists('snews_'.$_SESSION['langx'].'.php')) {include('snews_'.$_SESSION['langx'].'.php');}else{
                $_SESSION['langx'] ='en'; [/color]
       $l = array();
Make these changes in the file, use the included snews.php for help:
DON'T USE REPLACE FUNCTION IN YOUR EDITOR

name' INTO name_'.$_SESSION['langx']
description' INTO description_'.$_SESSION['langx']
title' INTO title_'.$_SESSION['langx']
text' INTO text_'.$_SESSION['langx']

name  INTO name_".$_SESSION['langx']."
description  INTO description_".$_SESSION['langx']."
title  INTO title_".$_SESSION['langx']."
text  INTO text_".$_SESSION['langx']."

5. Access your site as admin, insert a news/article/category in EN, then switch to XX, and write them again the second language.
Logged

Joost

  • Guest
Multi Languages
« Reply #36 on: March 16, 2007, 08:53:17 PM »

Looks good!

I think I am going to give it a try this weekend.
I noticed that changing the language (on your site)  brings you to the home. Am I correct?
Logged

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #37 on: March 16, 2007, 10:17:53 PM »

Quote from: Joost
Looks good!

I think I am going to give it a try this weekend.
I noticed that changing the language (on your site)  brings you to the home. Am I correct?
Hi,
You are correct.
I'm not an expert php/html, I'm learning to use these languages.
If you know how to fix, please tell me.

I supposed that if you choose your language, then you read your language.
I set that the default language is the same of your browser, then if that is not available, the language becomes English.

If you want to try the mod, at beginning, test it in a new DB.
There are a lot of little changes in snews.php.

Leonardo
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Multi Languages
« Reply #38 on: March 19, 2007, 01:18:34 PM »

@leo,
my main concern is that you remove the possibility of reverting simply to a snews single.
now, after many headaches, I think I have cracked it.
If you are game, try this on a test server.

Basically, it is the same, but I have made a small function that decides what field is added/upddated/called depending on the session.
If no language is initially set, it uses site default... but am still using your browser lang detection.

function to go into snews.php
Code: [Select]
//quick field selection routine.
function multiLangPick($field){
switch (true){
case $_SESSION['langx'] == '' : $f = $field ; break;
case $_SESSION['langx'] == s('language') : $f = $field ; break;
case $_SESSION['langx'] != s('language') : $f = $field.'_'.strtolower($_SESSION['langx']); break;
default: $f = $field;
}
return $f;
}
then alter your changes to
Quote
'name' INTO multiLangPick('name')
'description' INTO multiLangPick('description')
'title' INTO multiLangPick('title')
'text' INTO multiLangPick('text')

name  INTO ".multiLangPick('name')."
description  INTO  ".multiLangPick('description')."
title  INTO  ".multiLangPick('title')."
text  INTO  ".multiLangPick('text')."
in index.php, (note-- I am forcing session to uppercase, largely because I have directories setout for each language labeled with uppercase, just for any language specific items plus site lang is usually defined with uppercase by default.)
Quote
if (!isset($_SESSION['langx']) && !$_GET['lang'])
{$_SESSION['langx']=strtoupper(substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2));
}
else{ if($_GET['lang'])
$_SESSION['langx']=strtoupper($_GET['lang']);
}
include('snews.php');
then in language function
Quote
// LANGUAGE VARIABLES
function l($variable) {
   if ($_SESSION['langx'] != 'EN' && file_exists($_SESSION['langx'].'/snews_'.$_SESSION['langx'].'.php')) {
      include($_SESSION['langx'].'/snews_'.$_SESSION['langx'].'.php');} else {
   $l = array();
To quickly add another new language, I have the following in an included php file. (make an article, and include the php file)
Code: [Select]
if ($_POST['make']) {
$lang_def= strtolower(clean(cleanXSS($_POST['lang_def'])));
$lang_name = 'name_'.$lang_def;
$lang_description = 'description_'.$lang_def;
$lang_title = 'title_'.$lang_def;
$lang_text = 'text_'.$lang_def;

$query = "ALTER TABLE categories ADD ".$lang_name." varchar(100) NOT NULL";mysql_query($query);
$query = "ALTER TABLE categories ADD ".$lang_description." varchar(255) NOT NULL";mysql_query($query);
$query = "ALTER TABLE articles  ADD ".$lang_title." varchar(100) default NULL";mysql_query($query);
$query = "ALTER TABLE articles  ADD ".$lang_text." longtext";mysql_query($query);
}else{?>


Language definition for subsite (2 letters, lowercase)





}
?>
Logged
Of all the things I have lost, it is my mind that I miss the most.

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #39 on: March 19, 2007, 04:46:39 PM »

@philmoz
I changed back my DB and tried your changes.
I did another change:

Code: [Select]
// LANGUAGE VARIABLES
function l($variable) {
    if ($_SESSION['langx'] != 'EN' && file_exists($_SESSION['langx'].'/snews_'.$_SESSION['langx'].'.php')) {
        include($_SESSION['langx'].'/snews_'.$_SESSION['langx'].'.php');} else {
    $_SESSION['langx'] != 'EN'
    $l = array();
Because, if the user has another language it doesn't work.
I did the changes directly in my website, that is my test server.

I didn't test the last code you provided, the one to add a new language.

Thank you for your solution, it is cleaner.

Leonardo
Logged

Joost

  • Guest
Multi Languages
« Reply #40 on: April 04, 2007, 06:28:09 PM »

Behind schedule, but here is my report on Leo's mod, using  the modded snews.php from the language.zip:

At first everything looked alright. The default language was shown. I added some text, but when I changed to the second language, I got this error.
Fatal error: Cannot redeclare db() (previously declared in /home/snews_nl.php:17) in
/home/snews_nl.php on line 17

I wasn't  certain if the manual told me to install 1 or 2 snews.php copies or 1, so I tried both ways.  It didn't make any difference. I also tried changing include('snews_nl.php'); to include_once('snews_nl.php'); or irequire_once('snews_nl.php'); . This also made no difference, besides the fact that require_once does a better job at killing the engine.

For who needs to know (Leonardo perhaps): I ran this test on a Gentoo/Apache server.
Logged

Joost

  • Guest
Multi Languages
« Reply #41 on: April 05, 2007, 06:01:58 PM »

Leonardo has made a new installkit for me. It works great!

It took me 5 minutes to change the configuration and install. Adding content was confusing at the beginning, there is a learning-curve for the admin. You have to be very consistent in adding content or categories in the right order. For good use of the sef-url, the admin has to think about language-neutral words.

What i do like very much, is when you change the frontpage, it happens with one click for both languages. That also happens for the category-order. The total design, forces symmetry on site-structure.

So far it has only been a fifty minute exercise. I only added a 3 categories and two pages. Further exploring and reports will follow. Here is the test site: http://oostoever.com/amsterdam/
Logged

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #42 on: April 30, 2007, 10:52:54 PM »

I change a little the .htaccess file, I added these lines:

Code: [Select]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/$ index.php?lang=$1 [L]
The new link for change language will be:
site.com/en/ instead of  site.com/?lang=en
or
site.com/fr/ instead of  site.com/?lang=fr

I suppose that the language is ONLY TWO letters, and non category has two letter name.

I think it is possible to modify the .htaccess file in order to create a "directory" for the language:

site.com/en/category
...

I'll try to work on it, whiteout change deeply the snews.php file.

Leonardo
Logged

Joost

  • Guest
Multi Languages
« Reply #43 on: April 30, 2007, 11:32:36 PM »

You mean that eventually it could be something like: site.com/en/category/page/
Nice! :)
Logged

Leonardo

  • Newbie
  • *
  • Karma: 2
  • Posts: 22
    • http://leonardoprosperi.com
Multi Languages
« Reply #44 on: May 01, 2007, 03:12:03 AM »

Almost complete.
Add these lines to the .htaccess file:

Code: [Select]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/index.php?(.*)$ $2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/$ index.php?lang=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/(.*)$ index.php?lang=$1&category=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/([a-z_]+)/([^/]+)$ index.php?lang=$1&category=$2&title=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/([a-z_]+)/([^/]+)/([^/]+)/$ index.php?lang=$1&category=$2&title=$3&commentspage=$4 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z][a-z])/([a-z0-9_-]+)/([0-9]+)/$ index.php?lang=$1&category=$2 articlespage=$3 [L]
Then change in snews.php:

Code: [Select]
$db['website']= 'yoursite.com/'.strtolower($_SESSION['langx']).'/';In index.php addreesses must be complete:
"site.com/en/" "site.com/fr/"

Example:
site.com/en/category/page/  in english
site.com/fr/category/page/    in french
site.com/category/page/      default languge

In admin mode, there is a problem, switching language manually doesn't work.
You need to login in both languages.
Also for let download a file, an absolute link (site.com/files/file.zip) is needed.

UPDATE: I update my website with these change only recently.

Leonardo
Logged
Pages: 1 2 [3] 4