Comments & Opinions


Home Page | Comments | Articles | Faq | Documents | Search | Archive | Tales from the Machine Room | Contribute | Set language to:en it | Login/Register


Don't try to be too smart

When you say "who try to be too clever gets beaten up"... at least, my mom used to say so. And I never listened to her. But let's start from the beginning.

As said a few days ago, I'm enjoying myself (somehow) doing some bugfixes and improvement in the CMS. And one of the improvement that was the most requested, is the ability to select the language used to display content. And here I need to explain something.

I found extremely annoying when some website (developer) try to be too clever and pretend to enforce to me some language that is not the one I want. For example, if I visit the site of some company and that begins with "Ohhhh... you're from the Netherlands, so I'll set the language to 'dutch' and send you to the .nl site instead..." 

FuckNO! I don't want to go to the .nl site if I didn't typed '.nl' in the address bar (especially if it is a news site or such) and I prefer to have the site in english (especially if I am looking for documentation). 

And sometimes, when the site insists a bit too much, it ends up in the blacklist.

So, when I developed the CMS I thought: what do I do normally? I set the languages I want in the browser. English first, then Italian, then Dutch and then Klingon or whatever. Hence, I'll set the CMS to check which languages the browser wants and try to use those.

And to me it seems perfectly logica. But probably this is what everybody thinks when they try to be 'too clever'. And this is the reason why when somebody complained about this 'functionality', I got a bit miffed. It sounded so logical to me..

But whatever, you live to learn (or something like that).

So, here I am rummaging into the code to add this "set language" function. That means, I need to use cookie. That I don't really like, but hey, what can you do? Unless I change EVERYTHING to have settings tossed left and right in all the links...

And that's why now we got the disclaimer: THIS SITE USE COOKIE! Yes, ONE cookie. Singular.

And to do the development, I began installing a copy of everything in local to do testing (also to avoid the 'it works on my laptop' problem).

First thing I discovered is that 'Swish', the search engine I am using on the site, seems that died sometimes in the past and I can't really find it anymore. Ok, bummer, at the momenti I'll disable and then I'll do something else. Not a big problem.

The change for the language was a lot less problmatic than I thought. So I started doing testing and one of the first was to add the disclaimer in the home page. And when I did it, the whole page got completely screwed up! Whathefu...???

Since the 99.9% of the changes were in the code related to display functions, not in the 'editing', I thought it was some problems in the building of the page or the encoding (ISO/UTF/ANSI/ASCI...) or maybe some problem in the server configuration, I was mostly thinking to limits in the size of the uploads. But no.

After several messing around I confirmed that the page was fucked up once uploaded in the database, so it is the 'editing' function that has a problem.

And a 'diff' between the old and new source returned something I wasn't expecting: one specific line:

# remove junk
-$content=~s/
-//g;

Whatthefuck? And I'm 100% sure that I didn't chaned this line. After a check in the old source I found the 'original' line:

# remove junk
$content=~s/^M//g;

And then a little light started to lit up.

That line contains '^M', that is CRTL-V-M, is a 'sortcut' in VI to insert the DOS carriage return character. The line of code is meant to remove all the dos-style end-of-line. I did that to 'clean' the content of the page once it is uploaded. Why ? Because I thought I was being clever...

BUT! For reason I'm not going into here, I'm using Code (Microsoft's code editor) to edit the code of the cms. And it works well, the problem is, it doesn't understand the '^M' thing. And it couldn't since it's a vi-specific thing. So it turned that line the way it looks up there. And that line at this point means "delete everything after the first end-of-line". That is NOT the intended result.

So... try to be clever...

Anyhow, I fixed it (if you're curious, the correct way to do so is "s/\r\n/\n/g") and now, up there in the page, there should be a link to set the language of the site.

Now is time to look at the other 'improvement': how to change things so users that are using a "screen reader" have less problems. This is going to be a lot more complicated I am afraid. Also because, if I understood correctly, the only way to do it 'right' is to rewrite the content of the site. And I have no intention of going down that road.

Ok, time to go back to work. Have a good year everyone.

Davide Bianchi
05/01/2021 12:22

Comments are added when and more important if I have the time to review them and after removing Spam, Crap, Phishing and the like. So don't hold your breath. And if your comment doesn't appear, is probably becuase it wasn't worth it.

6 messages post new

Daniele Levi

By Daniele Levi posted 05/01/2021 13:39 - reply

Eureka, funziona! Ora però mi devo scaRRicare il nuovo source e riadattarlo per le mia "intranet".

Va bè, vorrà direi che so cosa farò domani, con buona pace di mia moglie).

Ciaoooooo

-- Daniele Levi

Messer Franz

By Messer Franz posted 05/01/2021 13:51 - reply

Ricorda che se il debugging è la procedura per eliminare i bug, il programmare è quella per inserirli... e se proprio tocchi qualcosa che ti incasina tutto e non capisci cosa, non preoccuparti, aggiungi altri errori a caso e poi proponilo al brancodipaguri, dicendo che è ok ma ha un paio di bug di poco conto da sistemare*, e vedi che te lo comprano subito. poi si vergogneranno di non saperlo mettere a posto e la cosa finirà nel dimenticatoio.

 

*che a me ha sempre suonato come "vendo questa ferrari testarossa a mille euro in contanti anticipati non restituibili perchè devo trasferirmi e là dove vado a stare non posso usarla, non è perchè ti sto truffando..."

-- Messer Franz

Messer Franz

By Messer Franz posted 05/01/2021 13:53 - reply

ps: dura 29 secondi. Vale la pena.

https://www.youtube.com/watch?v=HluANRwPyNo

 

(belli anche "if programming was an anime")

-- Messer Franz

Jack

By Jack posted 05/01/2021 18:39 - reply

Ciao Davide,

Posso consigliarti una ulteriore modificuccia piccola piccola?

I link En e It rimandano alla home page, ma potresti facilmente modificarli per cambiare lingua senza cambiare pagina, visto che gli script lato server già funzionano. Ad esempio:

h**ps://www.soft-land.org/cgi-bin/doc.pl?doc=commenti/284&mode=setpreferredlanguage&language=it

apre la pagina già forzata in italiano...

-- Jack

Davide Bianchi

@ Jack By Davide Bianchi posted 06/01/2021 06:29 - reply

Posso consigliarti una ulteriore modificuccia piccola piccola?

ecchemipareva! gli dai un'unghia e quelli subito chiedono la palla sinistra, un rene, il fegato e due fette di chiappa tagliate fine vicino all'osso...

-- Davide Bianchi

Emi-ska

By Emi-ska posted 07/01/2021 17:09 - reply

eh... quanti problemi mi ha causato il carattere ^M per rilasci su linux scritti con editor windows... non sai quante volte ho dovuto depurare i files da quel carattere speciale!! Avevo un piccolo scriptino fatto ad-hoc solo per quello.

Grande cone al solito e buon anno!!

 

Emi-ska

-- Emi-ska

6 messages post new

Previous Next


This site is made by me with blood, sweat and gunpowder, if you want to republish or redistribute any part of it, please drop me (or the author of the article if is not me) a mail.


This site was composed with VIM, now is composed with VIM and the (in)famous CMS FdT.

This site isn't optimized for vision with any specific browser, nor it requires special fonts or resolution.
You're free to see it as you wish.

Web Interoperability Pleadge Support This Project
Powered By Gojira