You are here: Re: Too match text I think. « All PHP « IT news, forums, messages
Re: Too match text I think.

Posted by Steve on 10/11/06 23:08

sorry for the text-wrapping...

i'll try. you may have better luck with the hundreds of resources on the web
though.

what kind of content will you have? does it change much?

anyway, for starters your code should define constants for either sections
of text that are static or phrases (like in error messages). that way when
programming, you refer to the constant which elimenates language (except for
php) altogether. ex.:

define('ERROR_INVALID_DATA_TEXT', 45);
define('EMAIL', 53);

if (!isEmail($email)){ echo translate($language,
array(ERROR_INVALID_DATA_TEXT, EMAIL)); }

45 and 53 would refer to the db id of the item in a translation table.
translate(...) is a function you'd create that simply to query the db and
return the appropriate text.

if you have php 5, you can make this much more friendly.

========


class errors
{
static const $invalidData = 45;
}

class phrases
{
// constants here to define individual phrases
}

class words
{
static const $email = 53;
}

class language
{
private $_currentLanguage;
static function setLanguage($language){ $this->_currentLanguage =
$language; }
static function translate($id, $concat = null)
{
if (!is_array($id)){ $id = array($id); }
$text = array();
foreach ($id as $toText)
{
// get text from db from id supplied
$text[$id] = record['VALUE']; // ficticious record object from db
}
if (!$concat){ return $text; }
return implode($concat, $text);
}
}

======

if (!isEmail($email)){ echo language.translate(array(errors::$invalidData,
words::$email), true); }

anyway, an OO approach allows you segement and refer to language id's in a
grouped and ordered fashion rather than trying to achieve the same thing
with VERY LONG define names...plus, they can be static so that you don't
have to explicitly create an instance of each of them.

again, try and keep everything segmented - from code, html, and language. it
then becomes more manageable. the first thing i'd create is a front-end for
the db translation table so that you can integrate the defined table
constants and change them automatically as you update your table...

let's say you define things in code as i have done...error text, phrases,
and individual words. i chose these because the a word in one language by
itself may look totally different when it is in a phrase. and a phrase that
is imphatic may be worded *entirely* differently that the tone of a warning
or error. the other thing to consider is gender...which most languages have
(i didn't account for it in the translate(...) function example, but you get
the gist). here's what my translation table would look like:

create table language
{
id int null auto_increment primary ,
varName varchar(255) not null ,
lang int not null , // assume your
supported langs. in other linked table
type enum('error', 'phrase', 'word' not null , // mysql assumed and
not sure of syntax
gender int not null , // assume genders in
other linked table
value text
}
on primary;

i think from that, you can figure out the query for the translate(...)
function. as for auto-updating the errors, phrases, words...make each a
require_once page. after an entry in this table is updated from your
maintenance web page, have php query the db and output the data to file so
that the output is actually php language itself for each varName and id
returned from the query. for you as a programmer, you'll need to make sure
that an email is automatically generated so that the change is
announced...especially if you work on a team of developers.

anyway, that's the bulk of it as briefly and precisely as i can get here.
i18n is a huge topic of discussion. it is covered by many, many, MANY
approaches...this is just a basic way to cover the bases.

hope that gets you started.



"Frits van Leeuwen" <fleeuwen@wanadoo.nlx> wrote in message
news:452d6cfb$0$13688$dbd4b001@news.wanadoo.nl...
| You are right. That's why I asking for help.
| So, can you help me step by step to fix a DB for my text?
|
| "Steve" <no.one@example.com> schreef in bericht
| news:10dXg.196$di5.75@newsfe06.lga...
| > your architecture is all wrong. separate the language from the html as
| > much
| > as possible. either store a page's content in a db or in it's own file
for
| > each language you intend to support...or keep each language in its own
| > directory and redirect to that directory as a virtual server. you cannot
| > hope to be able to maintain one page of code showing all language
versions
| > between switch statements.
| >
| > look for 'programming i18n' on google to shorten the learning curve.
| >
| > hope that helps.
| >
| >
| > "Frits van Leeuwen" <fleeuwen@wanadoo.nlx> wrote in message
| > news:452d5699$0$45649$dbd4f001@news.wanadoo.nl...
| > | Hello,
| > | I have index.php and language.php
| > | At index.php are buttons for choose language.
| > | In language I set a cookie and go back to index.php. (I'm happy, it's
| > | working)
| > |
| > | But index.php has too match text I think.
| > | In the following code, I show you "**** English text ****" and
| > "****Dutch
| > | text ****" thise are all the same texts. The difrence is the language.
| > But
| > | when you look to the code, You will see 3 times Enlis text and 3 times
| > Dutch
| > | text. I think it has to be one time for both of them.
| > |
| > | This is index.php
| > |
| > | <?php
| > | if (isset($_COOKIE["LeeuwendeelTaal"]))
| > | {
| > | switch ($_COOKIE["LeeuwendeelTaal"])
| > | {
| > | case "EN": // ENGLISH
| > | ?>
| > | <html>
| > | <head>
| > | <title>Begin Leeuwendeel.info</title>
| > | </head>
| > | <body link="#0000FF" vlink="#800080" alink="#00FFFF" text="#FF0000"
| > | bgcolor="#FFFFE1">
| > | <div align="center">
| > | <table border="1" width="100%" id="table1" style="border-width: 0px"
| > | height="530">
| > | <tr>
| > | <td style="border-style: none; border-width: medium">
| > | **** English text ****
| > | </td>
| > | <td rowspan="1" style="border-style: none; border-width: medium">
| > | <p align="right"><img border="0" src="images/underconstruction.gif"
| > | width="480" height="379"></p>
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | <!--vlag NL-->
| > | <p align="right"><a href="/language.php?ln=NL"><img border="0"
| > | src="knoppen/vlagNL.jpg" width="33" height="20" alt="Klik hier,
wanneer
| > u
| > de
| > | site in het Nederlands wilt lezen."></a></p>
| > | <!--vlag EN-->
| > | <p align="right"><a href="/language.php?ln=EN"><img border="2"
| > | src="knoppen/vlagEN.jpg" width="33" height="20" alt="Click here, when
| > you
| > | like to read the website in English."></a></p>
| > | </td>
| > | </tr>
| > | </table>
| > | </div>
| > | <p align="center"><font size="1">Last change:
| > |
| > | <?php
| > | break; // einde ENGLISH
| > |
| > | case "NL": // NEDERLANDS
| > | ?>
| > | <html>
| > | <head>
| > | <title>Begin Leeuwendeel.info</title>
| > | </head>
| > | <body link="#0000FF" vlink="#800080" alink="#00FFFF" text="#FF0000"
| > | bgcolor="#FFFFE1">
| > | <div align="center">
| > | <table border="1" width="100%" id="table1" style="border-width: 0px"
| > | height="530">
| > | <tr>
| > | <td style="border-style: none; border-width: medium">
| > | **** Dutch text **** </td>
| > | <td rowspan="1" style="border-style: none; border-width: medium">
| > | <p align="right"><img border="0" src="images/underconstruction.gif"
| > | width="480" height="379"></p>
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | <!--vlag NL-->
| > | <p align="right"><a href="/language.php?ln=NL"><img border="2"
| > | src="knoppen/vlagNL.jpg" width="33" height="20" alt="Klik hier,
wanneer
| > u
| > de
| > | site in het Nederlands wilt lezen."></a></p>
| > | <!--vlag EN-->
| > | <p align="right"><a href="/language.php?ln=EN"><img border="0"
| > | src="knoppen/vlagEN.jpg" width="33" height="20" alt="Click here, when
| > you
| > | like to read the website in English."></a></p>
| > | </td>
| > | </tr>
| > | </table>
| > | </div>
| > | <p align="center"><font size="1">Laatste wijziging:
| > |
| > | <?php
| > | break;
| > |
| > | default:
| > | ?>
| > | <html>
| > | <head>
| > | <title>Begin Leeuwendeel.info</title>
| > | </head>
| > | <body link="#0000FF" vlink="#800080" alink="#00FFFF" text="#FF0000"
| > | bgcolor="#FFFFE1">
| > | <div align="center">
| > | <table border="1" width="100%" id="table1" style="border-width: 0px"
| > | height="530">
| > | <tr>
| > | <td style="border-style: none; border-width: medium">
| > | **** Dutch text ****
| > | </td>
| > | <td rowspan="1" style="border-style: none; border-width: medium">
| > | <p align="center"><img border="0" src="images/underconstruction.gif"
| > | width="480" height="379"></p>
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | **** English text ****
| > | </td>
| > | </tr>
| > | <tr>
| > | <td style="border-style: none; border-width: medium">
| > | <p align="center"><a href="/language.php?ln=NL"><img border="0"
| > | src="knoppen/vlagNL.jpg" width="165" height="100" alt="Klik hier,
| > wanneer
| > u
| > | de site in het Nederlands wilt lezen."></a>
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | <p align="center"><a href="/language.php?ln=EN"><img border="0"
| > | src="knoppen/vlagEN.jpg" width="165" height="100" alt="Click here,
when
| > you
| > | like to read the website in English."></a>
| > | </td>
| > | </tr>
| > | </table>
| > | </div>
| > | <p align="center"><font size="1">Laatste wijziging / Last change:
| > |
| > | <?php
| > | break; // einde geen keuze
| > |
| > | }
| > | }
| > |
| > | else
| > | {
| > | setcookie("LeeuwendeelTaal");
| > | ?>
| > | <html>
| > | <head>
| > | <title>Begin Leeuwendeel.info</title>
| > | </head>
| > | <body link="#0000FF" vlink="#800080" alink="#00FFFF" text="#FF0000"
| > | bgcolor="#FFFFE1">
| > | <div align="center">
| > | <table border="1" width="100%" id="table1" style="border-width: 0px"
| > | height="530">
| > | <tr>
| > | <td style="border-style: none; border-width: medium">
| > | **** Dutch text ****
| > | </td>
| > | <td rowspan="1" style="border-style: none; border-width: medium">
| > | <p align="center"><img border="0" src="images/underconstruction.gif"
| > | width="480" height="379"></p>
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | **** English text ****
| > | </td>
| > | </tr>
| > | <tr>
| > | <td style="border-style: none; border-width: medium">
| > | <p align="center"><a href="/language.php?ln=NL"><img border="0"
| > | src="knoppen/vlagNL.jpg" width="165" height="100" alt="Klik hier,
| > wanneer
| > u
| > | de site in het Nederlands wilt lezen."></a>
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | </td>
| > | <td style="border-style: none; border-width: medium">
| > | <p align="center"><a href="/language.php?ln=EN"><img border="0"
| > | src="knoppen/vlagEN.jpg" width="165" height="100" alt="Click here,
when
| > you
| > | like to read the website in English."></a>
| > | </td>
| > | </tr>
| > | </table>
| > | </div>
| > | <p align="center"><font size="1">Laatste wijziging / Last change:
| > | <?php
| > | }
| > | ?>
| > |
| > | <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d-%m-%Y"
| > | startspan -->11-10-2006<!--webbot bot="Timestamp" i-checksum="12558"
| > | endspan --></font></p>
| > | </body>
| > | </html>
| > |
| >
| --------------------------------------------------------------------------------
| > | Mijn Postvak In wordt beschermd door SPAMfighter
| > | 4017 spam-mails zijn er tot op heden geblokkeerd.
| > | Download de gratis SPAMfighter vandaag nog!
| > |
| > |
| >
| >
|
| --------------------------------------------------------------------------------
| Mijn Postvak In wordt beschermd door SPAMfighter
| 4017 spam-mails zijn er tot op heden geblokkeerd.
| Download de gratis SPAMfighter vandaag nog!
|
|

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация