Reputation: 117
First of all, I'm totally new to PHP, so I'll need a bit more explanation. I'm trying to make a Multi-language site using PHP, the problem is; when I create a new folder like: domain.tld/test/location
(location is new in this case), the language files which are located at domain.tld/test
, are of course not imported. How can you clarify where these files NEED to be coming from?
Script
<?php
// include language configuration file based on selected language
echo realpath(dirname(__FILE__));
$lang = "en";
if(isset($_GET['lang'])){
$lang = $_GET['lang'];
}
require_once("lang.".$lang.".php");
?>
Upvotes: 0
Views: 46
Reputation: 7485
Try:
require_once __DIR__ . '/../lang.' . $lang . '.php';
Alternatively you could load upfront for all your Php files see:
auto_prepend_file
Upvotes: 0
Reputation: 425
Paths in php are like path in many languages. If you want to go backward, you add ../
before the path
require_once('../file/in/prev/dir');
I really suck at path, so whenever I have to make sure of one, I try it in my terminal. Maybe this can help you figure out where your file is.
However, I don't get why and how you need to do it this way... I mean, if you have one file for each language, why not doing it in HTML ? The main point of dealing with PHP is that you don't want to duplicate files, which is what you're doing.
You might be looking for Relational Database in which you'd have a table with generic content and another one with tranlated content. For example
Article :
|id| date |
|1 |8/8/08|
Translated Content :
|id| content |lang|
|1 | Hello | en |
|2 | Bonjour | fr |
and intermediate table :
|article_id|content_id|
| 1 | 1 |
| 1 | 2 |
Hope it helps
Upvotes: 1