-
-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translation #31
Translation #31
Conversation
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); There's My browser's header:
|
$lang = (isset($_GET['lang'])) ? $_GET['lang'] : $lang;
$lang_file = INCLUDE_PATH . '//lang/' . LANGUAGE . '.json';
$lang_file_content = file_get_contents($lang_file); Also you may want to use string realpath ( string $path ) to check if |
"Anime Scene Search Engine": "", | ||
"Browse a file": "", | ||
"Drag & Drop Anime ScreenShot / Ctrl+V / Enter Image URL": "", | ||
"Please read <a href=\"/faq\">FAQ</a> to understand what can / cannot be searched": "<a href=\"/faq\">FAQ</a>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not a good idea to put html tags in object keys :\
I also wanted to translate pages like about.php and faq.php |
Thanks for the feedback. In retrospective, I can see that the approach was not the best for the project. I will be working in a better way to do it. Thanks for your comments. |
I've been working in a simple approach to translate the web pages with the less effort possible.
The result, the following code. I hope you like it.
Use
The use it's pretty simple, in the PHP file to be translated, just include the file that acts as translator, and use the function
lang()
The
lang()
function search the keyword on the language files, if no language file exist or the keyword is not found, the original text is returned, if the keyword and file are found, the translated phrase is returned. The current language it's selected by the$_SERVER['HTTP_ACCEPT_LANGUAGE']
directive.The language files are in JSON format, to make possible the implementation (on a easy way) to JavaScript and another languages.
Only the index page was translated (To Spanish, because i'm Mexican). Just for testing, also the
template.json
will help to any translation. And the button of search is being displayed in Chinese (for Chinese users, also just for testing).If you can give any kind of feedback i'll be happy.