Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I configure "smart" language-switch buttons in an included HTML header?

Participant ,
May 16, 2021 May 16, 2021

Nutshell: Does a button in an included header know what page it is on?

 

Background: I am in the process of completely re-coding some bilingual websites that were generated using Netobjects Fusion. Each site has a homepage and complete web structure in English and a parallel structure in Spanish. So I have a page: aboutus.html and aboutus-es.html & so on. The Spanish page (home-es) is below the English home page (index.html. Every page has 2 language switch buttons in the header: English and Spanish actually as flags. The buttons take you to the respective home page - Not best for the user but it was easier for me :).  (Using Google-Spanish or equivalent is not an acceptable solution for us.) The sites need to be completely rebuilt but I am satisfied with the basic structure and plan to retain that for the time being. All of this was easy in Fusion and I am trying to save myself a lot of work and pain by having included headers, footers, menus etc. in the pages that I will code in HTML. While open to other suggestions, my reading so far indicates that using server-side includes with w3-include-html attribute or PHP would be the most practical solution, assuming my host allows it (am asking).  

 

Questions: I want the language buttons, which are in the included headers, to take the user to the equivalent page in the other language rather than always to the home page. I am hoping that I can use some simple JS to have the button go look on the page it finds itself in for the correct link. That means the buttons will have to "know" what page they are on. Is all of this feasible? Does it depend on how I include the headers? Is there a better way to include the headers with this functionality in mind?

3.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021

yep, and by the way, the last two are blocking errors... the last log does not run

console.log("'------------------'");

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2021 May 18, 2021

I would argue that is down to wayward coding management, trying to output something that hasnt been declared.........hummm. l guess lm a bit more organised as l would not really attempt to do that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021

Let me try to contextualize this approach. In fact it is very very usefull... (remember that I have adopted an agile methodology for a long time ago)...

 

good practice for declaring variables is that all var's are declared at the top of the file. so far... why not...

 

however, let's imagine an application context during development, and so we have a whole block composed of several functions specific to data management. preceded by the declarations of the variables specific to this whole mechanism... so far so good...


now, let say that we want to provide the system with a particular functionality specific to the smoothing / formatting of data ... so we will be towards the bottom of the file to add new functions... and on this occasion, we may have to deploy a panoply of variable ... for my part, I declare them just before these functions in the lower part of the file ... in order to have them on hand and especially to act (modification, deletion, grouping object, transtyping ... etc ...) according to the advancement of needs and development ...

 

as soon as we need an injection in one of the previous functions specific to data management (the upper blocks)... we just have to add a /* TODO VARIABLE _var_name USAGE NOT CONFIRMED */ preceding the injection of this variable in the concerned blocks... and hop, the Javascript engine won't complain... (because of the two reading passage of Javascript, using variable in the code before declaring it) and so we can preserve our comfort and flexibility of writing and injection... free to us to remove anything whgen code is over... and if the var doesn't go to the top...

 

an other approach will be to have a separate file added... sometimes I also use this technic, but that will require a second declaration in the first file.

 

Object VAR are often quite good for such elasticity... but those two last comments are not the subject... the subject was why using var before declaring them...

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2021 May 18, 2021

I guess its all about the workflow you use, dodgy or otherwise. The concensus of opinion, if you do some Googling about the use of 'var' in modern day web-development, suggests that var is somewhat considered to be less than needed now. Maybe I, plus those that think its not necessary just don't complicate procedures, whilst some like to overcomplicate procedures for some reason, only known to them.

 

using 'var' alone is not very forgiving in the fact that information can be re-assigned to it, which is good IF that is what the intention is BUT in a long complicated script you can easily mistakenly re-assign information to it that may have a huge impact on the script, whereas using 'const' for information that you do not want re-assigned is much safer and a much better way of working.  

 

I'm just moving forward, I think, trying to apply best practices which are available today.

 

P.S.

But there again, with all due respect, you find use for .dwt templates......enough said, that's really frightening.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021

you are 100% right, I agree with your vision. (without sarcasm)


it's like the developers who consider that the initialization of a const can only be done inside an if statement on the ternary mode, and this although the block scoped is respected on a traditional if.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2021 May 18, 2021
quote

you are 100% right, I agree with your vision. (without sarcasm)


it's like the developers who consider that the initialization of a const can only be done inside an if statement on the ternary mode, and this although the block scoped is respected on a traditional if.


By B i r n o u

 

You agree with my vision and I'm 100% right, if only I could take you seriously, someone that uses DW, .dwt and var - I cant be 100% confident.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021

don't despair, if one day I have the time and we manage to share a beer around a pub (finally reopened after this confinement) I could teach you the benefits, and wonders, of using templates with Dreamweaver.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021

Well at least that provided a good laugh to start the day. What's the next lesson, using tables for layout and how to deal with IE5 quirks?

 

Anyway onwards and upwards, or even sideways, backwards -whatever suits.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

no kidding, don't tell me that IE5 is out... I was still publishing DOM using layer and all...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2021 May 17, 2021

If you decide to do this manually, you may wish to create a persistent cookie that "stores" the end user's preferred language for their next visit.

https://www.tutorialrepublic.com/javascript-tutorial/javascript-cookies.php

 

Also read what Google Developers recommend.

https://developers.google.com/search/docs/advanced/crawling/managing-multi-regional-sites.

 

Nancy O'Shea— Product User, Community Expert & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021
quote

If you decide to do this manually, you may wish to create a persistent cookie that "stores" the end user's preferred language for their next visit.

https://www.tutorialrepublic.com/javascript-tutorial/javascript-cookies.php


By Nancy OShea


In a previous reply, I was thinking about using `session` variabales. After reading this reply, I can fully support using `cookies` instead. Rather than all of the JavaScript confusion, just set the cookie when the relevant flag is clicked and the `cookie` variable will be available each and every time and well throughout the site.

 

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021
quotejust set the cookie when the relevant flag is clicked and the `cookie` variable will be available each and every time and well throughout the site.

========

Right, @BenPleysier.  Or until the end user clears cookies from their browser. 

 

Also, let's not forget to mention the occasional PITA user who has --for reasons of their own -- disabled cookies and scripts in their browser settings.  

 

<noscript><p style="background-color:yellow; color: orangered; font-weight:900; font-size: 125%">JavaScript is disabled. Some site features will not work without it. For a better experience, enable scripts in your browser now and hit refresh (F5).</p></noscript>

 

Nancy O'Shea— Product User, Community Expert & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2021 May 18, 2021

seriously, if people still disable JavaScript, I wonder what they can really see on the web ????
moreover some time ago I struggled like crazy to disable Javascript on Firefox ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

@B i r n o u you are right. But why should the browser go through an extra proces when a simple HTTP request will suffice. All of the effort is processed on the server rather than in the browser.

 

This is not unlike sites requiring a login that typically set a cookie once your credentials have been verified, and you are then free to navigate to all parts of the site so long as that cookie is present and validated. Once again, the cookie just contains data and isn’t harmful in and of itself.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

of course @BenPleysier, I have never imposed a Javascript based solution, the use of a cookie can also be a very feasible alternative, among others, among others.

 

the only remark I made was about the presence, or not, of a button indicating the current language. And I was just proposing a Javascript based solution, because that was the original request of the OP

 

quote

I am hoping that I can use some simple JS to have the button go look on the page it finds itself in for the correct link.


By Galeodan

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021
quote

of course BenPleysier, I have never imposed a Javascript based solution, the use of a cookie can also be a very feasible alternative, among others, among 

 


By B i r n o u

 

Dont you have to get permission from the user to install a cookie on their system these days? I havent used a cookie for years so l dont know what the criteria is these days, locally or globally. All l know is as a user if any website starts to want to install a cookie on my system l usually decline unless its something l desperately need to access, but as l say maybe you only need to inform your intentions that you are about to invade the users computer based on certain criteria only.

 

EDITED

Well, from a quick read about cookies on Google, it's suggested that by law (in the UK anyway) if you intend to install any sort of cookie on a users computer you need to obtain their permission first.

 

So we are saying that the extra trouble of popping up a modal window or some other form of communcation with the user and explicity explaining what your cookie does when its installed on their computer, plus if the user declines the cookie then they wont have any further interaction with the current web-page or the web-page will be disfunctional is simpler than 15 lines of descreet javascript which works silently in the background within the law and doesnt infest itself into the users browser.

 

Sure cookies could be an option but based on the above one which risks alienating a percentage of users or providing them with a disfunctional experience, right?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

If cookies are such a problem, which I doubt, then, as an altrnative, you could use Local Storage. The disadvantage with Local Storage is that it is client side only.

 

For more, see: What is the difference between local storage vs cookies?

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021
quote

If cookies are such a problem, which I doubt, then, as an altrnative, you could use Local Storage. The disadvantage with Local Storage is that it is client side only.

 

For more, see: What is the difference between local storage vs cookies?


By BenPleysier

 

 

Well you could consider all these alternative options but in my opinion the most simplest is the implemention of a javascript option.

 

The only confusion, which you mentioned as a reason to look at other options, was what the OP actually required. Birnou interpreted this differently to me. Both of us had genuine reasons for supplying the suggestions we did, his being and quite correctly including the 'second' flag really offered no significant functionality. My reason to include the second flag was purely based on if it bought any visual clarity or visual impact, which really is a decision for the OP to consider. They seemed to confirm, for now at least, their choice was to include the second flag and a simple javascript script was provided to do that.

 

Its not for me to say but if someone wants to further complicate a simple process by using cookies or local storage then that has to be their choice of course.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

I am not saying that you are wrong. All I am saying is that cookies are a simpler alternative with an added advantage that returning viewers are immediately confronted with the language of their choice.

 

Let's face it, isn't it nice that when you return to a website where you have to log in, the remember me checkbox allows you immediate access? Thanks to cookies. Do you really think that people are put off by seeing a message that tells them to accept cookies? Most are so used to seeing these alerts that they don't even bother to read them.

 

To my way of thinking, it is the cookie that Google Analytics leaves behind which causes the problem in the UK. The tracking that goes on there and the on-selling of this information without the user's knowledge. That is what gives cookies a bad name, and to think that developers are including this render blocking Scheisse in all of their pages.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021
quote

I am not saying that you are wrong. All I am saying is that cookies are a simpler alternative with an added advantage that returning viewers are immediately confronted with the language of their choice.


By BenPleysier

 

Well give us a working example with 2 flags - English and Spanish which take you to the appropriate/reciprocal language page when clicked upon and inserts a green border around the appropriate image and let's see. I dont know much about cookies but since you seem to its obviously dead easy so bake up some code and share it here. I'm all for anything that makes life easier?

 

 Do you really think that people are put off by seeing a message that tells them to accept cookies? Most are so used to seeing these alerts that they don't even bother to read them.

 

By BenPleysier

 

Depends whether or not the user really wants access to the page. If it was my local national supermarket brand and I needed food for sure I probably would reluctantly accept the cookie but some small obscure website that I probably didn't need much I personally wouldnt bother as I would be scepitical of what was being loaded onto my computer.

 

quote

 

To my way of thinking, it is the cookie that Google Analytics leaves behind which causes the problem in the UK. The tracking that goes on there and the on-selling of this information without the user's knowledge. That is what gives cookies a bad name, and to think that developers are including this render blocking Scheisse in all of their pages.


By BenPleysier

 

I just dont really like the idea of my privacy being infringed when its strictly not necessary - you know all those ads that follow you around the place. Im sure a user could get back to the language of their choice by just clicking one of the 2 flags rather than the chance some users may be put off by the cookies downloading option.

 

I tend to look at things from the angle of the user not just what I want to do as a developer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

Well give us a working example with 2 flags 

Use Bing and you will find an example from Ray of WebAssist

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021

Thats just a simple cookie that remembers a language chosen by the user, its not actually useful in terms of clicking on a flag or button which then takes you to the reciprocal page in the optional language. To be honest I'm not even sure why the OP wants to do this. To my thinking a user either wants one or the other language, so does  it matter if they are not whisked away to the reciprocal page in the other language, but rather to the 'entry' page for the chosen language instead. This seems to be growing to be more complex that what is strictly necessary in my opinion and the extra work involved really isnt worth the benefits.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

<OFF TOPIC, ALTHOUGH THIS IS RELATED SOMEHOW>

 

so I specify, this debate that I open has nothing to do with Pros or Cons cookies usage... just an analysis of a new fact that follows

 

I don't know how the policies that are carried out in Australia, in England, in the United States... and so on are perceived.... but here in France when we visit a site for the first time, we hit the famous window (appeared with the RGPD) asking us if we accept or not the cookies... as this box distinguish all the various types of cookies...
until there nothing new... users are becoming more and more sensible to it


let me get an example, once the torpor of the users passed (once again here in France), users don't really complain to see this dialog box and on the contrary they play the game by browsing and invalidating some choices


all functional cookies are generally preserved... only the ones from partners are removed...

 

and that's my point...


there are more than a hundred of them (partners), even several... which is in itself... frightening... but let's go further... we refuse them all... no problem... well yes... there is a problem


visit for the experience (sorry it's a commercial link) https://www.marmiton.org/ and refuse all partner cookies... and try to access a recipe... now a new dialog box proposes... either you accept the cookies (all of them), or you take a premium account...
and this allows us to unmask the wolves that have entered the sheepfold... right?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021

Is that a for or against cookies? The way I read it is you dont particularly like the idea but I could be wrong.

 

The other point that keeps being mentioned here is using a cookie to go back to the language of the users choice. Well how do we know what that language is. I could be a user flicking from language to language to see how it is interpreted, which cookie should be deployed the English or Spanish? I might be Spanish but the last page I visited might be the English content which would presumably set an English cookie unless of course we bring another layer of complexity to the field by asking the user which language they prefered to see onload of the website.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2021 May 19, 2021
quote

 

I don't know how the policies that are carried out in Australia, in England, in the United States... and so on are perceived.... but here in France when we visit a site for the first time, we hit the famous window (appeared with the RGPD) asking us if we accept or not the cookies... as this box distinguish all the various types of cookies...
until there nothing new... users are becoming more and more sensible to it

 

By B i r n o u

 

Similar in the UK and its becoming disruptive in my opinion. Night after night I surf onto news websites an up pops that bloody 'cookies' box. I just get so annoyed by it I don't bother most of the time, unless I'm desperate - customer lost. Why do I need a cookie downloaded to my computer just to read about 3 sheep that have escaped their field...........mind boggles. As you say they are being used as a source of distrubuting your movement and what you are viewing. I'm not necessarily convinced its for their own purposes to better enhance their website either. There's money to be made, laws or no laws, someone will find a way around it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines