Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Multi-Language Mod - sNews 1.7  (Read 3447 times)

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Multi-Language Mod - sNews 1.7
« on: January 06, 2011, 05:32:11 PM »

REVISION & UPDATE NOTICE: Jan.10, 2011: Several of the steps (below) have been revised and updated
to clear up stuff that was not working properly. Steps that have been updated are noted as such.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I decided to take a shot at working out this Multi-Language mod for sNews 1.7 after reading Fred's posts which were in response to requests from Sparco and Stephane made back in April and May of 2009.  

This Mod is based on the same approach used by the sNews 1.6 version by etatus with some notable changes. The instructions below apply to a fresh, un-modified (default) sNews 1.7.1 package.

What it Does: This mod allows you to publish content in a language other than, and in addition to, English. When site visitors visit your site, they can choose which language to view your site in from a set of language text-links on the Home page. When another language is chosen, the site interface language and its content switches to whatever is available for that language.

What we need to Add:
1. A duplicate set of prefixed d-base tables in the same database for each additional language you publish content in.
2. A new Language Variables file in the lang folder for each language used.
3. Modifications to the snews.php file, the .htaccess file, and text-links added to the template (index.php) file.

Pre-Mod PREPARATION: As is the case whenever making numberous modifications, make back-up copies of:
    - your existing database,
    - snews.php file,   - index.php file   - .htaccess file

    - Language Variables File: Make up the language variables file for the language you are adding and save it in the lang folder.
      Be sure that you have all of the variable-value strings in it to match the EN.php file you are already using.
      Your file-name will be whatever language you are using. Example - FR.php for french.... RO.php for Romanian... etc.

STEP ONE: Database Table Set
Each language added to your site will require another set of tables in your existing database.
- Make up a new .sql file and copy in the same table-set already used in your database for english content.
  You don't need any data INSERTS in the content tables, but keep the same INSERT strings in the settings table.
- Add the prefix for your language to all table-name and INSERT table-name instances.

- In this case, I am adding French language capability, and my french_1.7.sql file contains:
Code: [Select]
<?php // DO NOT COPY THIS TAG

--
-- 
table-set for french language added to a default snews 1.7 package
--
-- -----------------------------------------------------------------------------

DROP TABLE IF EXISTS fr_articles;
-- ---- 
Create french Articles Table:
CREATE TABLE `fr_articles` (
`idint(11primary key auto_increment,
`titlevarchar(100) default NULL,
`seftitlevarchar(100) default NULL,
`textlongtext,
`datedatetime default NULL,
`categoryint(8NOT NULL default '0',
`positionint(6) default NULL,
`extraidvarchar(8) default NULL,
`page_extravarchar(8) default NULL,
`displaytitlechar(3NOT NULL default 'YES',
`displayinfochar(3NOT NULL default 'YES',
`commentablevarchar(5NOT NULL default '',
`publishedint(3NOT NULL default '1',
`description_metavarchar(255) default NULL,
`keywords_metavarchar(255) default NULL,
`show_on_homeenum('YES','NO') default 'YES',
`show_in_subcatsenum('YES','NO') default 'NO',
`artordersmallint(6NOT NULL default '0',
`visiblevarchar(6) default 'YES',
`default_pagevarchar(6) default 'NO',
KEY show_on_home (show_on_home)
);


DROP TABLE IF EXISTS fr_categories;
-- ---- 
Create fr_Categories table:
        
CREATE TABLE `fr_categories` (
`idint(8primary key auto_increment,
 
`namevarchar(100NOT NULL,
 
`seftitlevarchar(100NOT NULL,
 
`descriptionvarchar(255NOT NULL,
 
`publishedvarchar(4NOT NULL default 'YES',
 
`catordersmallint(6NOT NULL default '0',
 
`subcatint(8NOT NULL default '0'
);

-- ---- 
Insert data in fr_categories table:
INSERT INTO `fr_categoriesVALUES ('1''Uncategorized''uncategorized''''YES''1''0');

DROP TABLE IF EXISTS fr_comments;
-- ---- 
Create fr_comments table:
CREATE TABLE `fr_comments` (
 
`idint(11primary key auto_increment,
 
`articleidint(11) default '0',
 
`namevarchar(50),
 
`urlvarchar(100NOT NULL,
 
`commenttext,
 
`timedatetime NOT NULL default '0000-00-00 00:00:00',
 
`approvedvarchar(5NOT NULL default 'True',
 
KEY articleid (articleid)
);

DROP TABLE IF EXISTS fr_extras;
-- ---- 
Create fr_extras table:
CREATE TABLE `fr_extras` (
`idint(8primary key auto_increment,
 
`namevarchar(40NOT NULL,
`seftitlevarchar(100) default NULL,
`descriptionvarchar(100NOT NULL
);

-- ---- 
Insert date in fr_extras table:
INSERT INTO `fr_extrasVALUES (1'Extra''extra''The default extra');

DROP TABLE IF EXISTS fr_settings;
-- ---- 
Create fr_settings table:
CREATE TABLE `fr_settings` (
 
`idint(8primary key auto_increment,
 
`namevarchar(20NOT NULL,
 
`valuevarchar(255NOT NULL
);

-- ---- 
Insert data in fr_settings Table:
INSERT INTO `fr_settingsVALUES (1'website_title''sNews 1.7');
INSERT INTO `fr_settingsVALUES (2'home_sef''accueil');
INSERT INTO `fr_settingsVALUES (3'website_description''sNews CMS');
INSERT INTO `fr_settingsVALUES (4'website_keywords''nouvelle, site, nouvelles');
INSERT INTO `fr_settingsVALUES (5'website_email''info@mydomain.com');
INSERT INTO `fr_settingsVALUES (6'contact_subject''Formulaire de contact');
INSERT INTO `fr_settingsVALUES (7'language''EN');
INSERT INTO `fr_settingsVALUES (8'charset''UTF-8');
INSERT INTO `fr_settingsVALUES (9'date_format''d.m.Y. H:i');
INSERT INTO `fr_settingsVALUES (10'article_limit''3');
INSERT INTO `fr_settingsVALUES (11'rss_limit''5');
INSERT INTO `fr_settingsVALUES (12'display_page''0');
INSERT INTO `fr_settingsVALUES (13'display_new_on_home''');
INSERT INTO `fr_settingsVALUES (14'display_pagination''');
INSERT INTO `fr_settingsVALUES (15'num_categories''on');
INSERT INTO `fr_settingsVALUES (16'show_cat_names''');
INSERT INTO `fr_settingsVALUES (17'approve_comments''');
INSERT INTO `fr_settingsVALUES (18'mail_on_comments''');
INSERT INTO `fr_settingsVALUES (19'comment_repost_timer''20');
INSERT INTO `fr_settingsVALUES (20'comments_order''ASC');
INSERT INTO `fr_settingsVALUES (21'comment_limit''30');
INSERT INTO `fr_settingsVALUES (22'enable_comments''NO');
INSERT INTO `fr_settingsVALUES (23'freeze_comments''NO');
INSERT INTO `fr_settingsVALUES (24'word_filter_enable''');
INSERT INTO `fr_settingsVALUES (25'word_filter_file''');
INSERT INTO `fr_settingsVALUES (26'word_filter_change''');
INSERT INTO `fr_settingsVALUES (27'username''098f6bcd4621d373cade4e832627b4f6');
INSERT INTO `fr_settingsVALUES (28'password''098f6bcd4621d373cade4e832627b4f6');
INSERT INTO `fr_settingsVALUES (29'enable_extras''NO');
INSERT INTO `fr_settingsVALUES (30'last_date'NOW());
INSERT INTO `fr_settingsVALUES (31'file_extensions''phps,php,txt,inc,htm,html');
INSERT INTO `fr_settingsVALUES (32'allowed_files''php,htm,html,txt,inc,css,js,swf');
INSERT INTO `fr_settingsVALUES (33'allowed_images''gif,jpg,jpeg,png');

// DO NOT COPY THIS TAG ?>


Other Languages - you would prefix your tables with a different prefix to match the language you will be using, which would be the same as the language variables file-name. Example, if your language variables file-name was DE.php, the prefix for your table and insert names would be de_

Add your new language tables to your database by importing your new file.

UPDATED: STEP TWO: Add text-links to your template (index.php file.
Some people like to use little flag icon images for language links but... when you think about it.... the world has changed a lot and most countries have many languages spoken in them. So, I am only providing text-links for this project. You can add any image icons you want later once you have it all working.

Very simple.... just add thse links wherever you want in your index.php file... I put mine above <div id="logo"> for testing purposes.
NOTE: The second link has FR in it which corresponds to the fr_ prefix used for the d-base tables and FR for FR.php language variables file in the lang folder. You will need to change it to suit the language prefix and file-name you are using.
Code: [Select]

<?php // Language links
echo '<p><a href="index.php?sessionlang=EN">English</a>&nbsp;&nbsp;<a href="index.php?sessionlang=FR">French</a></p>';
?>


<div id="logo">


Still in your index.php file - in the <head> part - add ../ to the file-path string for your css stylesheet.
If you have other stylesheet and/or javascript inclusion strings in the same location, you'll likely need to do the same with them to keep the working,
So... the file-path to the default CSS file will be:
          <link rel="stylesheet" type="text/css" href="../css/style.css" />

STEP THREE: snews.php modifications:

1. Search for return $db[$variable]; - it is on line 34 in the default 1.7.1 snews.php file.
    Copy and paste the following just above it in your file:
Code: [Select]
<?php // DO NOT COPY THIS TAG

# ML-Mod 1.7 (1)
$db['sessionlang'] = 'EN'// Default session language (DB tables without lang prefix)
$lang session_lang();
# Set Database prefix as Session prefix.
if ($variable == 'prefix') { return $db['prefix'].($lang==$db['sessionlang'] ? '' $lang.'_' ); }
        
# END: ML-Mod 1.7 (1)

// DO NOT COPY THIS TAG 
?>


UPDATED:
2. Below the above function we were just working in, you'll find function site() preceded with: //SITE
    Above it (in between the two functions) we need to add ONE new function.
    - function session_lang sets the language chosen by a user for his/her session on the site.
Code: [Select]
<?php // DO NOT COPY THIS TAG

# ML-Mod 1.7 (2) - new function
// SESSION LANGUAGE - sets language chosen by a user for his/her session on the site
function session_lang() {
   if (isset(
$_POST['sessionlang'])) $_SESSION['lang'] = $_POST['sessionlang'];
   else if (isset(
$_GET['sessionlang'])) $_SESSION['lang'] = $_GET['sessionlang'];
   if (
$_SESSION['lang']) $lang $_SESSION['lang'];
   else {
      
$lang=db('sessionlang');
      
$_SESSION['lang'] = $lang;
   }
   return 
$lang;
}
# END: ML-Mod 1.7 (2)

// DO NOT COPY THIS TAG 
?>


UPDATED:
3. Just below those new functions.... replace the existing //SITE function with this one:
    It adds the language prefix into all URLs generated on the site.
Code: [Select]
<?php // DO NOT COPY THIS TAG

//SITE - Automatically detects the scripts location.
function site() {
        
$lang session_lang(); # ML-Mod 1.7 (3) - Pull in the User's Session Language Prefix.
$host 'http://'.$_SERVER['HTTP_HOST'];
$directory dirname($_SERVER['SCRIPT_NAME']);
$website $directory == '/' $host.'/' $host.$directory.'/'.$lang.'/'// LANGUAGE Prefix added to end.
return $website;
}

// DO NOT COPY THIS TAG ?>


4. Search your snews.php file this line - // LANGUAGE VARIABLES
    The string under it chooses the language variables file based on whatever language is entered into the Admin Settings panel.
    That setting no longer works with this Multi-Language Mod.
    Comment out the string by adding a couple of forward slashes to the start of it.
    Paste this new section under the commented-out string... it switches language variable files based on the Users chosen language.
Code: [Select]
<?php // DO NOT COPY THIS TAG

# ML-Mod 1.7 (4) - Language File Switch  ----------------------------
        
$lang session_lang(); // - Pull in the Session Language (S-L)
if(file_exists('lang/'.$lang.'.php')){ // if lang-file-name matches Session lang
    include('lang/'.$lang.'.php'); // include that lang-file
} else { include('lang/EN.php'); } // If not, include EN.php
# END: ML-Mod 1.7 (4) --------------------------------------------------

// DO NOT COPY THIS TAG 
?>


UPDATED:
5. Finally, If you had modified your //TITLE function before, replace your modded one with the original.
    If you're doing this Mod for the first time, ingmore this step. There is no longer any need to modify this function.

NEW STEP:
After spending some time comparing this Mod with the same in a working sNews 1.6 install, I finally figured out why nothing was processing to the database from the administration panels.

As it turned out, all of the admin action links in the sNews 1.6 (snews.php file) had index.php in them, while those in the sNews 1.7 (snews.php file) did not. So I added index.php to one of the non-working SUBMIT button' action strings... tested it... and it worked again.

So... we need to add index.php to 38 admin action strings in the sNews 1.7 snews.php file.
Search your file for ?action=.
Some will look like '._SITE.'?action= while others will not have '._SITE.' before the ?action= part.

Add index.php to every one - just before the ?action= part in all 38 instances, so they look like:
      '._SITE.'index.php?action= or index.php?action= whichever the case may be.

STEP FOUR: Modify the .htaccess file (the last step)
- Open your .htaccess file, comment out the last two lines in the file and paste in the following below them so they look like this:
Code: [Select]

#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php?category=$1 [L]

## ML-Mod 1.7 (6) - new rules replace the 2 strings above.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_/\-]+)$ index.php?category=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Z][A-Z])/index.php?(.*)$ $2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Z][A-Z])$ index.php?sessionlang=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Z][A-Z])/$ index.php?sessionlang=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Z][A-Z])/(.*)$ index.php?sessionlang=$1&category=$2 [L]


And that's the end of the modifications.

When you visit your home page, you should see the language links in the top left corner of the page.
Click your language link.... click the login link at the bottom of the page, long into your language administration area and create a test article in your new language. It will be saved into the new articles table you added for your new language.

Final Note: As is the case with all Mods I post... this Mod comes with no guarantees or expressed warranty. It seems to perform well for me but there might be a little glitch that I did not run across. it is important that you test it out a lot before using it on a production installation. Please post any problems you might experience below and we'll do our best to sort them out.

Keys...
« Last Edit: January 10, 2011, 06:04:29 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 199
Re: Multi-Language Mod - sNews 1.7
« Reply #1 on: January 08, 2011, 05:23:02 PM »

Hello Keyrocks,
I'm actually trying to add the ML Mod.

It's working but not completely.
If I put just above return $db[$variable]; the new code :
Code: [Select]
# ML-Mod 1.7 (1)
$db['sessionlang'] = 'EN'; // Default session language (DB tables without lang prefix)
$lang = session_lang();
# Set Database prefix as Session prefix.
if ($variable == 'prefix') { return $db['prefix'].($lang==$db['sessionlang'] ? '' : $lang.'_' ); }
        # END: ML-Mod 1.7 (1)
It doesn't work at all, I've got a blank page. But if I put it just after like this :
Code: [Select]
// if you don't need it just leave it blank
'prefix' => ''
        );
return $db[$variable];
# ML-Mod 1.7 (1)
$db['sessionlang'] = 'EN'; // Default session language (DB tables without lang prefix)
$lang = session_lang();
# Set Database prefix as Session prefix.
if ($variable == 'prefix') { return $db['prefix'].($lang==$db['sessionlang'] ? '' : $lang.'_' ); }
        # END: ML-Mod 1.7 (1)
}
It's working. I can have English or French.

After that I tried to add Categories or Articles and I can't.
Nothing happen when I add a new categorie, It's also impossible to edit the default categorie : Uncategorized
If I try it goes directly to the Home page !
Same for Articles, If I try to add an article in the default Uncategorized categorie nothing happen.

I'd like to know if it's working for you ?
I've tried all of this with a fresh default install of snews 17.

Thanks in advance.
Stephane



Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #2 on: January 08, 2011, 07:04:45 PM »

Hello Keyrocks,
I'm actually trying to add the ML Mod. It's working but not completely.
It's working. I can have English or French. After that I tried to add Categories or Articles and I can't.
Nothing happen when I add a new categorie, It's also impossible to edit the default categorie : Uncategorized
If I try it goes directly to the Home page ! Same for Articles, If I try to add an article in the default Uncategorized categorie nothing happen.
I'd like to know if it's working for you ?
Stephane

Thanks for giving this a test-run Stephane.
My testing was limited only to checking that the language files were switching, adding a new article to the french, and testing various page links to be sure they all had the EN/ or other language prefix added to them.

I did not make any categories our publish any comments to see that they were working.
I will do some more testing on my localhost install and see how it's working.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #3 on: January 08, 2011, 08:54:47 PM »

@ Stephane... since this Mod is not yet working 100%... I am moving it to Programming/Mods-in-development Board.

Testing Observations:

Comments - English:
- Can create comments to existing article OK.
- Cannot edit a comment - get returned to the Home Page after clicking the Edit link.
  Notice that index.php is missing from the Edit link URL.
  Putting it in the URL (manually) gets the comment Edit panel and an edit saves OK.
        Bad URL: http://localhost/snews17ml/EN/?action=editcomment&commentid=11
        Good URL: http://localhost/snews17ml/EN/index.php?action=editcomment&commentid=11

I am assuming this may be caused by the .htaccess file changes... since they are essentially same as used in the 1.6 version (which works correctly). I am not good with .htaccess rules at all... so we may need help on this one from somenone who does.

UPDATE: - As it turned out, it wasn't an .htaccess issue at all. Our problem was caused by the fact that all of the admin-action links did not have index.php in them as they are in the sNews 1.6 snews.php file. So the original modification instructions in my lead post are now updated.
« Last Edit: January 10, 2011, 06:10:21 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 199
Re: Multi-Language Mod - sNews 1.7
« Reply #4 on: January 08, 2011, 11:05:43 PM »

OK I see that.
 Did you see the FredK solution ?
It's seems to working fine. But I change a little to have a default language instead of cliking flag link.
Not sure if it is the good way.

http://snewscms.com/forum/index.php?topic=9881.0

I will continue the test on this version also.
Thanks
Stephane
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #5 on: January 10, 2011, 06:13:29 PM »

@ Stephane... and anyone else following this Mod...

I solved the issue of administration action links not working, and have tested the modifications extensively.
I have updated the original modifications in my lead post to reflect the changes.
Please go through those steps again - with a default sNews 1.7 installation - and test it some more.
I have not found any problems so far.... so it looks OK now.  8)

Once we determine that it is now working properly... I will move this thread back to the Mods Board.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 199
Re: Multi-Language Mod - sNews 1.7
« Reply #6 on: January 10, 2011, 07:18:00 PM »

Well I'm trying to see how it's work.
But I have a very strange problem as soon as I add the new function above  $db[$variable];
I've got a blank page.

The new function must look like this, right ?
Code: [Select]
// DATABASE VARIABLES
function db($variable) {
$db = array(
// Edit here for the database information only
// MySQL host
'dbhost' => 'localhost',
// Database name
'dbname' => 'snewsML',
// Database Username
'dbuname' => 'root',
// Database password
'dbpass' => 'root',
// Table prefix for multiple sNews systems on one database
// if you don't need it just leave it blank
'prefix' => ''
);
# ML-Mod 1.7 (1)
$db['sessionlang'] = 'EN'; // Default session language (DB tables without lang prefix)
$lang = session_lang();
# Set Database prefix as Session prefix.
if ($variable == 'prefix') { return $db['prefix'].($lang==$db['sessionlang'] ? '' : $lang.'_' ); }
        # END: ML-Mod 1.7 (1)
        
return $db[$variable];
}
# ML-Mod 1.7 (2) - new function
// SESSION LANGUAGE - sets language chosen by a user for his/her session on the site
function session_lang() {
   if (isset($_POST['sessionlang'])) $_SESSION['lang'] = $_POST['sessionlang'];
   else if (isset($_GET['sessionlang'])) $_SESSION['lang'] = $_GET['sessionlang'];
   if ($_SESSION['lang']) $lang = $_SESSION['lang'];
   else {
      $lang=db('sessionlang');
      $_SESSION['lang'] = $lang;
   }
   return $lang;
}
# END: ML-Mod 1.7 (2)

I really don't know why it doesn't work. Everything else seems to be good.
I'm testing with a fresh sNews 17.

Stephane
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #7 on: January 10, 2011, 07:24:29 PM »

That looks correct to me Stephane.
I don't know why you get a blank page doing this.... I do not.
I am working on a Win XP machine with XAMPP installed as my server system.
It works OK for me in both IE8 and FireFox.

Maybe I should bundle up my working file-set as a ZIP and put it up where you cand ownload it and see if it works for you.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 199
Re: Multi-Language Mod - sNews 1.7
« Reply #8 on: January 10, 2011, 07:27:18 PM »

Hum, very strange.
I'm working on OS X with MAMP and Firefox too.
Maybe a problem with MAMP ?

I continue testing....

Thx,
S.
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #9 on: January 10, 2011, 10:29:26 PM »

You can download a ZIP of my complete working package here.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • sNews Dude
  • ULTIMATE member
  • *****
  • Karma: 134
  • Posts: 2806
Re: Multi-Language Mod - sNews 1.7
« Reply #10 on: January 11, 2011, 02:39:53 AM »

There's an error in the description of STEP THREE:
Quote
STEP THREE: snews.php modifications:

1. Search for return $db[$variable]; - it is on line 34 in the default 1.7.1 snews.php file.
    Copy and paste the following just above it in your file:

In the complete working package keyrocks' posted above, the appropriate code part is placed directly after "return $db[$variable];". I initially got the same problem with blank site as Stéphane but with this change, the site loads fine. So now I can try the system. ;)

I would propose one modification, if I may. The new site() function will output the $lang part of the url as domain/EN/ or domain/FR/ etc. It might not make much difference but in keeping a nice looking (and universally working) url, I'd suggest changing the site() function to this:

Quote
//SITE - Automatically detects the scripts location.
function site() {
   $lang = session_lang(); # ML-Mod 1.7 (3) - Pull in the User's Session Language Prefix
   $host = 'http://'.$_SERVER['HTTP_HOST'];
   $directory = dirname($_SERVER['SCRIPT_NAME']);
   $website = $directory == '/' ? $host.'/' : $host.$directory.'/'.strtolower($lang).'/'; // LANGUAGE Prefix added to end
   return $website;
}


Problem
When clicking the link for my secondary language I get a 404 response with the following url
http://localhost:8888/snewstemplates/themes/multilang/se/index.php?sessionlang=SE
This is when using the same link construction as in the description, and verified by comparing to the complete package index.php.

Did a quick test while writing this, and found the solution (obvious really).
In my environment (Mac OS X, MAMP), the links must be like this to work:

Quote
<a href="<?php echo $sessionlang['EN']; ?>">English</a> | <a href="<?php echo $sessionlang['SE']; ?>">Svenska</a>
The other construction fails as it doesn't check snews.php or the db for what language might be used. I think. The url now becomes correct with no 404.
« Last Edit: January 11, 2011, 03:03:12 AM by Fred K (agentsmith) »
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #11 on: January 11, 2011, 04:27:03 AM »

Thanks for giving it a test-run Fred, much appreciated.  :)

1. The error in description of Step 3: I pasted ML-Mod 1.7 (1) in after the  return $db[$variable]; for Stephane since he had to have it there to work on his OS X Mamp install... he was getting a blank page with it above the return $db[$variable]; string. However, for anyone running this on a WinXP XAMPP machine, it won't work unless it is above it.

2. Lower-case Prefixes in URL: For me, on my WinXP machine.... using strtolower($lang) in the string returns a '404' page when I click the language text-links.... and it reverts back to the non-prefixed databse tables even while my French language file continues to display. So, for WinXP XAMPP installs, it would appear you don't want to use the strtolower($lang) mod in that string. We'll have to test this 'beast' online shortly (whenever I can get back into my test-bed domain... sigh...)

3. Links Modifications: Strange eh? Like the two above, this also seems to be Mac OS X related. (leaves me scratching my head without a Mac OS X machine to test on).
« Last Edit: January 11, 2011, 04:28:51 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • sNews Dude
  • ULTIMATE member
  • *****
  • Karma: 134
  • Posts: 2806
Re: Multi-Language Mod - sNews 1.7
« Reply #12 on: January 11, 2011, 07:17:07 AM »

3. Links behaviour

Oh, it gets weirder. I set up a completely fresh installation using your ML package from the link above and changed nothing at all. I have one standard db for English and one prefixed set of tables for Swedish. The only thing I did different was to use the official sNews 1.7.1 SQL file, to mimick a completely fresh installation. Naturally I duplicated the SQL file for the prefixed tables, and like your multilingual SQL file, the prefix is in lowercase, so they're similar in that respect. I also put an SE.php in the lang folder. Now, when I click the Swedish link on the index page, the resulting url I get is (same as before):

Quote
http://localhost:8888/multilingual//index.php?sessionlang=SE
Note the double slashes after "multilingual" in the url. However, the double slash issue goes away if I click on an article headline, or if I click the English language link (e.g select a different language).
All this is in Firefox 3.6 btw, although I expect the result to be the same in other browsers.
So, the fresh installation works, even with the odd looking index.php?sessionlang links. It just looks a little "weird". ;)
The benefit with this mod is you get even fewer files than when using the cookie-based solution, which is great.
If we can find a fix to the "this line must go here for windows but there for mac" issue, and maybe a prettier url solution, then it'll be awesome.

PS. The strtolower thing - when I try it in the fresh installation it doesn't work so you're right about it, and it's not just a windows thing. I get same behaviour with it now. Not sure why it worked so well earlier...
« Last Edit: January 11, 2011, 07:36:14 AM by Fred K (agentsmith) »
Logged

stephane

  • Full Member
  • ***
  • Karma: 6
  • Posts: 199
Re: Multi-Language Mod - sNews 1.7
« Reply #13 on: January 11, 2011, 02:32:50 PM »

Thanks for your package Keyrocks.

I'm actually testing with another complete fresh install with your package and I have a strange behaviour.

My link are like this :

On the English link the result is like this : http://localhost:8888/snews17-multilingual/FR/index.php?sessionlang=EN
On the French link : http://localhost:8888/snews17-multilingual/EN/index.php?sessionlang=FR

 ??? ???

Of course it's a complete mess up  :-\

@Fred K
I saw your last post in the cookies version. I will test it also.
Thanks a lot.
« Last Edit: January 11, 2011, 02:39:53 PM by stephane »
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6262
  • Semantically Challenged
    • snews.ca
Re: Multi-Language Mod - sNews 1.7
« Reply #14 on: January 11, 2011, 02:47:39 PM »

The folder for my project in the htdocs of my XAMPP (WinXP) is snews17ml.
The Home URL when the site is in default English mode is http://localhost/snews17ml/EN/

Clicking the French link gets me http://localhost/snews17ml/EN/index.php?sessionlang=FR which is to be expected since I was in English mode when I clicked the link.
Clicking Home while now in French mode gets me http://localhost/snews17ml/FR/

However, I notice that if I use the links Etatus posted in his Step 2 (for 1.6) which are  &sessionlang=EN and &sessionlang=FR instead of index.php?sessionlang=EN and index.php?sessionlang=FR they work too.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: [1] 2