使用数组显示不同语言的技术术语

I'm working on a multilinguistic site in four languages, where a lot of technical terms are used. To help me somewhat with the translations and to avoid having to look up and type in the same terms over and over, I thought I'd put them in an array, like this :

(file called vocabulary.php)

enter code here<?php $t1 = array("term 1 in language 1","term 1 in language 2","term 1 in language 3","term 1 in language 4"); $t2 = array("term 2 in language 1","term 2 in language 2","term 2 in language 3","term 2 in language 4"); ?>

Each page, regardless of the language it is written in, would have an include to the vocabulary.php file :

enter code here<?php include "vocabulary.php"; ?>

and a new variable, depending on the language the page is written in, for instance to get to the first position in the arays

enter code here<?php $lan = 0 ?>

An example sentence for a page written in language 1 would be :

enter code here<p>Some text <?php echo $t1[$lan]; ?> some more text <?php echo $t2[$lan]; ?> final text.</p>

This set-up works, but is there a way to simplify this ? I don't really want to set up a database to hold my vocabulary.

I'd advise doing a DB for simplicity, but it's completely your call. My suggestion will be based on the fact that you do not want to use a DB :)

I'd suggest something like this, to make it a bit easier for you:

Create a file for each language. For example, localization/0.php:

$t1 = "Test 123";
$t2 = "Test ABC";

localization/1.php:

$t1 = "Test 123 French";
$t2 = "Test ABC French";

The general idea is to name the variables exactly the same. Then, in your index file (or whatever is presently calling your vocabulary.php) just do a quick check for the language and include that language file. This way, you're only ever populating variables with the language that is being used. Example:

<?php include "localization/{$lan}.php"; ?>

This gives you the ability to refer directly to $t1 in all pages, without having to refer to an array. Again, though, the beauty of this is that you're only loading into memory what you have to, and you're not making a single I/O operation more than you would have anyway. You're simply going about it a bit different.

This won't offer crazy performance gains and it won't be much easier, but it'll allow for you to keep things neater and cleaner for easier updating and such.

Hope it helps!