<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pedro Oliveira on Medium]]></title>
        <description><![CDATA[Stories by Pedro Oliveira on Medium]]></description>
        <link>https://medium.com/@pnboliveira?source=rss-8f5a85047c0b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*51zOb0eW8XZg0PztyieRYA.jpeg</url>
            <title>Stories by Pedro Oliveira on Medium</title>
            <link>https://medium.com/@pnboliveira?source=rss-8f5a85047c0b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:26:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pnboliveira/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Behind the Code: 4th September Website Update]]></title>
            <link>https://medium.com/dwoliveiras-corner-of-code-and-entertainment/behind-the-code-4th-september-website-update-70d57ceec381?source=rss-8f5a85047c0b------2</link>
            <guid isPermaLink="false">https://medium.com/p/70d57ceec381</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[portfolio]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Pedro Oliveira]]></dc:creator>
            <pubDate>Mon, 05 Sep 2016 04:43:24 GMT</pubDate>
            <atom:updated>2016-09-19T08:20:05.100Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello! This is a new series of posts I’ll be writing in the coming months, to explain any and all things I do in relation to code. Whether it’s HTML, JavaScript or even C#, there’s always a reason behind it that makes an app or website work, and sharing it is the best I can do. And to start this off…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l9v4sbFrDjxLBh9AimNjNA.jpeg" /><figcaption>Before &amp; after: First version of the Portfolio vs. Ver. 1.5, launched yesterday.</figcaption></figure><p>To explain to you what I’ve been up to, I’ve been working on version 2.0 of my website, which is aimed to be a complete overhaul of its design and make the most usage of <a href="http://www.materializecss.com/">MaterializeCSS</a>. But because it was more time consuming than it should have been and since I wanted to keep the website updated <strong><em>while </em></strong>maintaining the original look, I’ve decided to do a Ver.1.5 of it, with some of the new content that will be in Ver.2.0. If you’re that TL;DR kind of person, here’s a changelog:</p><blockquote><strong>CHANGELOG:<br>- NEW: </strong>A tab bar, categorising every project I’ve worked on and what type it was;<strong><br>- NEW: </strong>A better card layout! Now with mini descriptions and sticky links, as well as a condensed version of the About section for mobile users;<br><strong>- NEW: </strong>Better language handling! There’s no need for two HTML pages, as everything is in one HTML file and it’s all thanks to jQuery;<br><strong>- FIXED: </strong>Some of the layouts were not up to form for mobile/ tablet users, mainly the about section. That has been corrected.</blockquote><p>Now, onto the real content, I’ll explain the one feature I’m glad I got in this (and hopefully, it’ll stay for Ver.2.0) which is the Language Detection and Switch using <strong>solely</strong> jQuery.</p><h3><strong>Language Detection + Switch</strong></h3><p>So, as a person who speaks two languages, I wanted my website to cater both the Portuguese speakers and branch out to English speakers. The thing is, during version 1.0, I had no idea how to approach that issue. And so came this solution…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*SaiUjasE5TEMkaChjcUVGw.png" /><figcaption>Structure of ver.1.0 of my website. That index.html was technically blank.</figcaption></figure><p>I had to use a total of <strong>three</strong> HTML pages for the whole page to be built on, and it consisted of a browser language-based redirect courtesy of the main index.HTML. If it detected the Portuguese language, it would redirect to the Portuguese website. If it was another language, it would redirect to the English version. This alternative wasn’t the one I was happy with initially, but it got the job done. So much so, it also got reused for the main page of the company I internshipped for between April and July, <a href="http://www.forgescom.pt/">FORGESCOM</a>.</p><p>But I was still struggling, and I wanted a fresh framework to display my website in the browser’s preferred language, <em>without</em> the need of three HTML files. So I started digging, and most of the answers would either require a hosting service (I currently don’t have one yet) or over-complicated it with display languages and the sort. But then I found two JSFiddles that caught my attention, and an idea came up.</p><p>When you check the Source code or use the Developer Tools on your browser, you’ll notice there’s some divs, aptly named <em>&lt;div class=”article pt” lang=”pt”&gt; </em>and<em> &lt;div class=”article en” lang=”en”&gt;</em>. (Keep these in mind, as they’ll have a purpose later.)<br>Those serve as identifiers for each language the website is written in, and as soon as it loads, it’ll display the correct one based on the user’s web browser, thanks to this code snippet in jQuery (present in <em>init.js) </em>:</p><pre>var known = {<br> en: true,<br> pt: true<br> };</pre><pre>// Browser language check, and make it default to English for more exposure<br> var lang = (navigator.language || navigator.userLanguage || ‘en’).substr(0, 2);<br> if (!known[lang])<br> lang = ‘en’;</pre><pre>// Search &lt;div&gt;s with an ‘article’ class &amp; lang attribute that’s equal to the variable ‘lang’ and make them visible<br> $(‘div.article[lang=’ + lang + ‘]’).show();</pre><pre>// Search &lt;div&gt;s with an ‘article’ class &amp; lang attribute that are not equal to the variable ‘lang’ and hide them<br> $(‘div.article[lang!=’ + lang + ‘]’).hide();</pre><pre>var $articles = $(‘.article’);</pre><pre>$(“.langButton”).click(function () {<br> var language = $(this).attr(“data-language”);<br> $articles.hide(); // hides them out<br> $(“.” + language).show(); // Shows the ones attribuited to the browser language.<br> });</pre><p>And, surprisingly, it worked, but it needed a language toggle, in case the person wanted to switch languages. That’s where the main HTML comes back in. Remember those <em>divs </em>I talked about earlier? I had to split them all up in different divs to do two main things, <strong>display the respective language</strong> and <strong>make it not break the page</strong>. That’s why the current HTML is structured in <strong>8 different language divs.<em> </em></strong>It’s somewhat troublesome later, but effective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xd69vOzgqkrPPvebMBbO9Q.png" /><figcaption>Main structure of the HTML page, showcasing the language identifiers.</figcaption></figure><p>And what was the end result, you ask?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FFairSameAmericankestrel&amp;url=https%3A%2F%2Fgfycat.com%2FFairSameAmericankestrel&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FFairSameAmericankestrel-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="1535" height="966" frameborder="0" scrolling="no"><a href="https://medium.com/media/b10a0f3b56465995f1ab4c54a0a26b77/href">https://medium.com/media/b10a0f3b56465995f1ab4c54a0a26b77/href</a></iframe><p>Basically it works on the fly now, instead of redirecting to another page and taking an extra half a second to 1 second to load. and the size of this little HTML file is <strong>59KB</strong>s, and its JS file is <strong>9KB</strong>s. It’s pretty lightweight, I might add!<br>You can check it out now, <a href="http://www.dwoliveira.com/">as we speak</a>!</p><p>Now, this was a great start to this “Behind the Code” series, and I want to keep doing more of these in the future! Let’s see how the coming months work for me. And about Ver.2.0 of my website, when I have juicy visuals to show you, I’ll write it up. :)</p><p><em>(P.S. You may have noticed there was a “stream” div in that main HTML screenshot. That was in the website since Ver.1.2 (a silent update) but I’ll explain it in a separate, Twitch-focused post!)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70d57ceec381" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dwoliveiras-corner-of-code-and-entertainment/behind-the-code-4th-september-website-update-70d57ceec381">Behind the Code: 4th September Website Update</a> was originally published in <a href="https://medium.com/dwoliveiras-corner-of-code-and-entertainment">Pedro, the Write-up</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>