close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

detect system language

Thread began 6/12/2020 3:52 am by Jonas | Last modified 12/01/2020 12:22 pm by Ray Borduin | 485 views | 7 replies |

Jonas

detect system language

How can I detect system language in a query?

I have found a site that very well describes how to build a multilingual website. The address is: https://www.apphp.com/tutorials/index.php?page=multilanguage-database-design-in-mysql

I intend to use method 4 for my project.

The article shows examples of what a sql query can look like to retrieve appropriate title according to the chosen language in the system.
I think this seems like a smooth solution. Or do you have any better suggestions?

According to another website, you can "pick" the browser language: https://www.geeksforgeeks.org/how-to-detect-browser-language-in-php/
I call the session "lang". And I want to set this to "substr ($ _ SERVER ['HTTP_ACCEPT_LANGUAGE'], 0, 2);"

I have two questions if I should use the examples from the above mentioned pages.
1. How do I write the same query with the WA MySQLi Recordset?
2. How do I create the session. Is this code correct:
<? Php
@session_start ();
if (! isset ($ _ SESSION ["long"])) {
$ _SESSION ["long"] = "substr ($ _ SERVER ['HTTP_ACCEPT_LANGUAGE'], 0, 2);";
}
?>

Is there any complete guide you offer on how to do this? It should be of great public interest.

Sign in to reply to this post

Ray BorduinWebAssist

1) You can create any query you want with the recordset. The code should work the same as in any example you are following.
2) You have too many quotes. I think it should be:

php:
<?php

@session_start();
if (! isset(
$_SESSION["lang"])) {
  
$_SESSION["lang"] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 02);
}
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

Thanks Ray! This works fine on the site I am working on - which contains two languages. But I now realize that those who have languages other than the two I set to detect, get a 404 error message. Is it possible to write the code so that all other languages, automatically go to, for example, English.
Here is the code I have on the index.php page:
<?php
@session_start();
if(true) {
$_SESSION["lang"] = "".substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) ."";
}
?>
<?php
// Redirect browser
header("Location: http://localhost:8888/bucketlistNyServer/" . $_SESSION['lang'] . "/index.php");
exit;
?>

Sign in to reply to this post

Ray BorduinWebAssist

<?php
@session_start();
if(true) {
$_SESSION["lang"] = "".substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) ."";
}
?>
<?php
if ($_SESSION["lang"] != "fr") $_SESSION["lang"] = "en";
?>
<?php
// Redirect browser
header("Location: http://localhost:8888/bucketlistNyServer/" . $_SESSION['lang'] . "/index.php");
exit;
?>

Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

Okay, so I have to go through every language there is, if I understand correctly?

Sign in to reply to this post

Ray BorduinWebAssist

Any page that has that code. I'd put that code into an include file and then put it on every page, so if you ever need to add a language in the future you can do it from one file.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jonas

No, what I mean was, I want to redirect those language that's not in the list to the en language. Is this possible without writing the code from every language?

Sign in to reply to this post

Ray BorduinWebAssist

I'm not sure what the second language you support is, but the line I added:


<?php
if ($_SESSION["lang"] != "fr") $_SESSION["lang"] = "en";
?>

basically says "if it isn't french, use english"

You use that line to set it to english whenever it isn't set to the second language you support.

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...