Rails 的 HTML lang tag

紅寶鐵軌客
Join to follow...
Follow/Unfollow Writer: 紅寶鐵軌客
By following, you’ll receive notifications when this author publishes new articles.
Don't wait! Sign up to follow this writer.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.
寫程式中、折磨中、享受中 ......
1.13K   0  
·
2021/04/11
·
2 mins read


攝影師:Esther,連結:Pexels

閒來無事,真的是沒事不要亂改 code,改了就會出事,還好...... 沒人發現,老闆也不知道!

話說,有一天讀到,在 HTML5 的 <html> 中,要加入 lang= 來標註網頁的語系,這樣,除了瀏覽器能更正確的編碼,對搜尋引擎 SEO 也會有幫助,加入這太簡單了,舉手之勞,一分鐘解決(本來想說一秒鐘的,做人要謙虛......)

lang= 語系,在 Rails 就是 params[:locale],不然就是 I18n.locale,台灣就是  zh-TW,這有疑問嗎?還好我有多花幾分鐘查,哈哈哈哈,原來不是,它的要求是 language-script-region-variant-extension-privateuse,也就是「語言」- 「字體」- 「地區」-「方言」- 「特殊附加資訊」,台灣就是:zh-Hant-TW,這也不難,下手!

<!DOCTYPE html>
<%# 台灣的繁體中文要設定為 zh-Hant-TW %>
<html

  lang= <%= I18n.locale.to_s == "zh-TW" ? "zh-Hant-TW" : I18n.locale.to_s %>

>

真的只要一分鐘,打包,有沒有 SEO 效果? 不知道,反正應該沒壞。

沒想到,有壞,真的,而且很怪,這樣一改了後,params[:locale] 竟然變成 zh-Hant-TW !!

不信?我的 byebug 就是這樣告訴我的:

(byebug) params[:locale] = "zh-Hant-TW"

不要問我為什麼?我真得不懂,有賢人可以指導一下原因跟理由嗎?

我又花了一分鐘把這行拿掉,原來想說那就改成 lang= 用 rails 的 zh-TW, 後來想想,算了,沒加也沒事,也不知道 Google 會不會給分,算了,少個香爐少個鬼吧。

話說,我進一步發現,這東西還有不同說法,在 w3schools 的繁中建議的是用 zh-Hant,不是 zh-Hant-TWw3c 好像也是說簡中用 zh-Hans什麼鳥啊,拿掉!

結果,我花了好幾個小時玩這個 lang=?


WriterShelf™ is a unique multiple pen name blogging and forum platform. Protect relationships and your privacy. Take your writing in new directions. ** Join WriterShelf**
WriterShelf™ is an open writing platform. The views, information and opinions in this article are those of the author.


Article info

This article is part of:
分類於:
標籤:
日期:
創作於:2021/04/11,最後更新於:2021/04/11。
合計:435字


Share this article:
About the Author

很久以前就是個「寫程式的」,其實,什麼程式都不熟⋯⋯
就,這會一點點,那會一點點⋯⋯




Join the discussion now!
Don't wait! Sign up to join the discussion.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.