What is the best way to make a multilingual site? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to make landing page on 2 languages, swapping language by click on the flag.
How I understand, I need to save language state in user's localstorage / cookies.
I see here 3 options:
Upload on user machine .json with content on 2 languages. At the opening of page script will check localstorage for availability of lang variable and after it fill page by JS.
Save lang variable in cookies, and at appeal to the server, server must make magic and send back page built on user language.
Make duplicates of each page in each language.
Question 1:
Which way better, when and why? (cases: one page landing, site with many pages)
Question 2:
When I make duplicates of page, is it normal to have no index.html in root directory at all, but:
/en/index.html
/ru/index.html
and .htaccess file that redirect to /en/ by default, check cookies for lang variable, and if exist redirect user to specific folder.

Question 1:
Option 1:
Good practice if you have some sort of frontend framework (like Angular or React).
But if you have a static (or only serverside rendering) page it is not really the way to go. Because it add unnecessary complexity to your code.
Option 2:
Good way to do it if you only have backend rendering (for example with PHP).
Option 3:
Do this only if you have static webpage (only HTML/CSS) which does not change. And you don't have programming experience at all.
Question 2:
Well no you always have a index.html but you can redirect to the index.html of the default language.

I would store each one of translations in a json file (en.json, ru.json) and change languages using url parameters. index.html?lang=ru (This way you don't have to handle different paths)
If the url parameter exists, save it on localstorage, load the respective json and fill the page with the tanslated strings.
If there is no url parameter, look in the localstorage for a language. If there is nothing there, assume a default (en, for example) and load the translated strings.

Related

How to make a working login functions for my website? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I am just entered this game since last December. Now I finished HTML CSS and a little bit of Java Script yet I got stuck at this stage: I can do basic styling but I don't know how to make it interactive.
So my question is :
how can I make a login function for websites, which can gives visitor an account (sign up, login, forgot password) that can do basic things like comment , add to basket and favorite a product?
Don't need to be specific, please just highlight which language is involved in which stage.
Thanks ahead.
Now I finished HTML CSS and a little bit of Java Script
So your site is what is called a static website.
If you want to allow login and data storing, you need a dynamic website, that requires one of this technologies:
PHP
ASP (check also ASP.NET)
Node.js (with express or http module)
Django (Python's library)
A few others...
All this technologies are called server-side languages/technologies, and the most used for long years has been PHP, that now has some strong rivals in terms of usage.
You can use only html/js to create a website. But, if you need authentication, post comments, a server side is needed.
A js can call easely an API to authenticate (server side) and post comments with XHR. You have to create it. You need to know how Authentication headers works for server side. You need to have a database (sql, file or nosql, it's your choice) to save the users datas and rights.

Linking pages together [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have been working with a knowledge graph where each unique subject has a number of properties. Each subject has a unique URI ex lets take this website: https://www.deutsche-digitale-bibliothek.de/person/gnd/118575775?lang=en
for a particular person
I know it is a stupid question but I am new to html and javascript. So if I have a link to that URI do I have to create an html file for each subject? What do /person/gnd/... refer to exactly?
Essentially, every slash after the domain is considered a route or pattern. The way that route works depends on the configuration of the web server.
Host-Based
Host based routing relies on the web server to route/forward the traffic, and in most cases it is in fact using a physical directory on the filesystem. This is the traditional way web applications worked.
Path-Based
Path based routing uses what is commonly referred to as a "front controller" to route the request. In this scenario, the web server routes/forwards all traffic to one file (commonly index.xxx). Inside that file you have an application router that matches patterns based on the URI. If it finds a match, that particular code will run and the result is returned.
Here is a link that also explains it: https://dzone.com/articles/the-three-http-routing-patterns-you-should-know
If I have a link to that URI do I have to create an html file for each subject?
Thank god no! An URL like http://example.com/some/path is basically a protocol (http://) + a server name (example.com) + a path (/some/path). The old-school way was to indeed have a resource for each path, but that is not required: given a certain path, the server is free to respond with whatever it wants.
I can't say that for sure but I highly suspect deutsche-digitale-bibliothek.de to have preformatted page for all people, and then custom person infos is being loaded thereafter. The bottom line is that it is both unecessary and not advised to, in the case when a lot of similar pages exist, have one HTML file for each of them.
What do /person/gnd/... refer to exactly?
That is the path. That's the segment that is sent to the server as part of the URL as specified in the HTTP protocol.

html header to send back in requests? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to solve a problem similar to the ones in this question and this one, basically tracking a sub-session for users by browser tab. The thing I'm trying to accomplish, though, is finding a way to set a request parameter to send back to the server with each request, whether it's a simple synchronous link click, a form post, or an ajax request. What occurred to me as a hopeful solution would be if I could set something in the html head that would be sent each time, though I haven't seen anything to suggest that it's possible. I'm hoping to find a solution that doesn't require wrapping all server requests in some sort of javascript to include the desired parameter.
We're using Rails on the backend.
Difficult question to answer without knowing which server side language you are using. Regardless, using php, perl, python, or any other language, you could generate a unique ID and append it as a query string to your links. If you don't want the ugly links, you can:
A. use .htaccess to perform a mod_rewrite to clean up the URL
B. use an additional cookie to track the sub-session
C. use pure javascript, not very reliable depending on the client browser though..
the method used to track depends on what capabilities you have, database, text file, etc.
Again, not much info to go on.

Can I read and edit files that belong to the website folder using only html and javascript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am creating a website that must be able to login using the credentials that are saved in a text file(login.txt).After logging in the person must be able to add and remove images(images folder).
These images will then later be used to create a gallery that all users will be able to view.
What I want to know is can i achieve these results by only making use of HTML and JavaScript or must i also make use of server side languages like php or asp.net ?
note : I have done a good amount of research and still wasn't able to find an accurate answer for this question.
Any advice will be useful. Thanks ahead...
Short answer: You have to use a server
I assume you already know Javascript, so my advice is use Node.js.
You have to use a server side language because other users need to see the gallery , besides the ones that are uploading. So you can't use localStorage to save the images, because the front-end is private to the user, not global to every user (like a database or a server).
Some suggestions:
Use a database for user details, is faster, safer, and more maintainable
Define a Rest API on the server-side
On the front-end make a Single page application (using desired framework/libraries), using TDD principle
You should to use a server side language.
And if you save the credentials in a text file then anyone can reach these infos with that file url. ( Eg: http://yoursite.com/login.txt )
What I want to know is can i achieve these results by only making use of HTML and JavaScript or must i also make use of server side languages like php or asp.net ?
You'll need something on the server. That something might be:
Web server software that supports using the PUT verb to put files in a directory on the server. The general term for this is DAV or, in the web context, WebDAV. Apache, for instance, supports it with mod_dav. I've never tried it, but it may be possible to set up Apache with simple authentication (probably not with a plain text username/password file, though) and enable WebDAV for authenticated users. Your client-side code could then send PUT requests via ajax.
A server-side programming environment of some kind whether that's PHP, ASP.Net, NodeJS, or something else.
A content management system of some kind that already provides the ability you would otherwise write.

Is Header or Javascript better for redirecting in PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am trying to redirect users to a specific page after a login. Are both equally effective? or is one better than the other?
Thanks
You cannot compare both methods!
JavaScript will only run on the client side, therefore you need to send HTML first, then execute the redirection.
Using PHP, you can directly forward the user. This is not only faster, but also the only applicable choice in terms of usablity.
You will also have a problem if JavaScript is disabled or you have got an error in your JS scripts (for whatever reason). Well, you could counter by using HTML meta redirects, but the pros of using server-side redirects just predominate.
Compared to client side JS, an HTTP redirect will:
Require less data to be send to the client for it to process the redirect instruction
Not cause the browser to behave badly when the back button is pressed
Work in browsers with JS blocked / disabled / otherwise failing
An HTTP Location header is almost always the better approach.
They are different.
One is server side (php) and the other is client side (js).
Usually it's done server side, so it's a transparent redirection (doesn't pollute browser history, back button, etc). I repeat: usually but it's not a rule.
PHP is faster - the whole page doesn't have to load first. You can just send the header and exit the script.

Categories