Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lang select #19

Merged
merged 21 commits into from
Jun 12, 2020
Merged

feat: lang select #19

merged 21 commits into from
Jun 12, 2020

Conversation

vltansky
Copy link
Member

@vltansky vltansky commented Jun 7, 2020

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

This is a draft feature. I didn't make tests for it yet.
Autocomplete prompt to select HTML lang attribute from this country list
Prompt looks like this:

? Select language »
>   English
    Abkhaz
    Afar
    Afrikaans
    Akan
    Albanian
    Amharic
    Arabic
    Aragonese
  ↓ Armenian

What do you think?

P.S
Video.

@vltansky vltansky marked this pull request as draft June 7, 2020 17:39
@vltansky vltansky requested review from roblarsen and coliff June 7, 2020 17:41
@lgtm-com
Copy link

lgtm-com bot commented Jun 7, 2020

This pull request introduces 1 alert when merging 316299f into 635ae3f - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@coliff
Copy link
Member

coliff commented Jun 8, 2020

interesting idea, though usually when setting a language on a webpage I also set the locale.. e.g. en-gb for a UK site or en-us if its for US etc.
https://en.wikipedia.org/wiki/Language_localisation#Language_tags_and_codes
So I wonder if it should also include these options too. I think it needs to be quick and easy to select an option from the list.

@vltansky vltansky closed this Jun 8, 2020
@vltansky
Copy link
Member Author

vltansky commented Jun 8, 2020

Closed it by mistake... I'll make a few changes and open a new one.

@vltansky
Copy link
Member Author

vltansky commented Jun 8, 2020

interesting idea, though usually when setting a language on a webpage I also set the locale.. e.g. en-gb for a UK site or en-us if its for US etc.
https://en.wikipedia.org/wiki/Language_localisation#Language_tags_and_codes
So I wonder if it should also include these options too. I think it needs to be quick and easy to select an option from the list.

I took a list of language codes (in en-us, en-gb format) from here.
That how it looks now:

? Select language »
>   af
    af-NA
    af-ZA
    agq
    agq-CM
    ak
    ak-GH
    am
    am-ET
  ↓ ar

Video

@vltansky vltansky reopened this Jun 8, 2020
@lgtm-com
Copy link

lgtm-com bot commented Jun 8, 2020

This pull request introduces 1 alert when merging 09cb6a8 into 635ae3f - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@coliff
Copy link
Member

coliff commented Jun 8, 2020

I think many of these are not valid, the country code needs to be 2 characters.. and I think many of the ones on that list are not needed (for example en-DE)... think we should look for a better source

@vltansky
Copy link
Member Author

vltansky commented Jun 8, 2020

Can you help me to find a good source?

@coliff
Copy link
Member

coliff commented Jun 8, 2020

Can you help me to find a good source?

sure, I'm looking now... :-)

@h5bp h5bp deleted a comment from lgtm-com bot Jun 8, 2020
@lgtm-com
Copy link

lgtm-com bot commented Jun 8, 2020

This pull request introduces 1 alert when merging 2ad3712 into 635ae3f - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@roblarsen
Copy link
Member

I had never researched what these actually are. They appear to be ISO 639-1 codes. Here's a list in CSV format.

alpha2,English
aa,Afar
ab,Abkhazian
ae,Avestan
af,Afrikaans
ak,Akan
am,Amharic
an,Aragonese
ar,Arabic
as,Assamese
av,Avaric
ay,Aymara
az,Azerbaijani
ba,Bashkir
be,Belarusian
bg,Bulgarian
bh,Bihari languages
bi,Bislama
bm,Bambara
bn,Bengali
bo,Tibetan
br,Breton
bs,Bosnian
ca,Catalan; Valencian
ce,Chechen
ch,Chamorro
co,Corsican
cr,Cree
cs,Czech
cu,Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic
cv,Chuvash
cy,Welsh
da,Danish
de,German
dv,Divehi; Dhivehi; Maldivian
dz,Dzongkha
ee,Ewe
el,"Greek, Modern (1453-)"
en,English
eo,Esperanto
es,Spanish; Castilian
et,Estonian
eu,Basque
fa,Persian
ff,Fulah
fi,Finnish
fj,Fijian
fo,Faroese
fr,French
fy,Western Frisian
ga,Irish
gd,Gaelic; Scottish Gaelic
gl,Galician
gn,Guarani
gu,Gujarati
gv,Manx
ha,Hausa
he,Hebrew
hi,Hindi
ho,Hiri Motu
hr,Croatian
ht,Haitian; Haitian Creole
hu,Hungarian
hy,Armenian
hz,Herero
ia,Interlingua (International Auxiliary Language Association)
id,Indonesian
ie,Interlingue; Occidental
ig,Igbo
ii,Sichuan Yi; Nuosu
ik,Inupiaq
io,Ido
is,Icelandic
it,Italian
iu,Inuktitut
ja,Japanese
jv,Javanese
ka,Georgian
kg,Kongo
ki,Kikuyu; Gikuyu
kj,Kuanyama; Kwanyama
kk,Kazakh
kl,Kalaallisut; Greenlandic
km,Central Khmer
kn,Kannada
ko,Korean
kr,Kanuri
ks,Kashmiri
ku,Kurdish
kv,Komi
kw,Cornish
ky,Kirghiz; Kyrgyz
la,Latin
lb,Luxembourgish; Letzeburgesch
lg,Ganda
li,Limburgan; Limburger; Limburgish
ln,Lingala
lo,Lao
lt,Lithuanian
lu,Luba-Katanga
lv,Latvian
mg,Malagasy
mh,Marshallese
mi,Maori
mk,Macedonian
ml,Malayalam
mn,Mongolian
mr,Marathi
ms,Malay
mt,Maltese
my,Burmese
na,Nauru
nb,"Bokmål, Norwegian; Norwegian Bokmål"
nd,"Ndebele, North; North Ndebele"
ne,Nepali
ng,Ndonga
nl,Dutch; Flemish
nn,"Norwegian Nynorsk; Nynorsk, Norwegian"
no,Norwegian
nr,"Ndebele, South; South Ndebele"
nv,Navajo; Navaho
ny,Chichewa; Chewa; Nyanja
oc,Occitan (post 1500)
oj,Ojibwa
om,Oromo
or,Oriya
os,Ossetian; Ossetic
pa,Panjabi; Punjabi
pi,Pali
pl,Polish
ps,Pushto; Pashto
pt,Portuguese
qu,Quechua
rm,Romansh
rn,Rundi
ro,Romanian; Moldavian; Moldovan
ru,Russian
rw,Kinyarwanda
sa,Sanskrit
sc,Sardinian
sd,Sindhi
se,Northern Sami
sg,Sango
si,Sinhala; Sinhalese
sk,Slovak
sl,Slovenian
sm,Samoan
sn,Shona
so,Somali
sq,Albanian
sr,Serbian
ss,Swati
st,"Sotho, Southern"
su,Sundanese
sv,Swedish
sw,Swahili
ta,Tamil
te,Telugu
tg,Tajik
th,Thai
ti,Tigrinya
tk,Turkmen
tl,Tagalog
tn,Tswana
to,Tonga (Tonga Islands)
tr,Turkish
ts,Tsonga
tt,Tatar
tw,Twi
ty,Tahitian
ug,Uighur; Uyghur
uk,Ukrainian
ur,Urdu
uz,Uzbek
ve,Venda
vi,Vietnamese
vo,Volapük
wa,Walloon
wo,Wolof
xh,Xhosa
yi,Yiddish
yo,Yoruba
za,Zhuang; Chuang
zh,Chinese
zu,Zulu

@vltansky
Copy link
Member Author

vltansky commented Jun 8, 2020

But this list not contains en-us, en-gb and etc. as @coliff proposed. It looks like a first list I used.

@roblarsen
Copy link
Member

The lang attribute (in no namespace) specifies the primary language for the element’s contents and for any of the element’s attributes that contain text. Its value must be a valid BCP 47 language tag, or the empty string. Setting the attribute to the empty string indicates that the primary language is unknown. [BCP47]

Here's the BCP 47 spec

https://tools.ietf.org/html/bcp47

I think we can safely use a subset. Can we let people who know better enter their own?

@vltansky
Copy link
Member Author

vltansky commented Jun 8, 2020

Sorry, I didn't understand your message.
By subset do you mean ISO 639-1?

@vltansky
Copy link
Member Author

vltansky commented Jun 8, 2020

We can add "custom" option to autoselect and put it second after "en". After choosing "custom" user will get another prompt where he can enter custom value (without validation - ?)

@roblarsen
Copy link
Member

Sorry, I didn't understand your message.
By subset do you mean ISO 639-1?

Yes, especially if we can let people type in something.

@vltansky
Copy link
Member Author

vltansky commented Jun 9, 2020

@roblarsen another ISO 639-1 autocomplete with "custom" option. What do you think?
@coliff I'd be happy if you could take a look too.
1.

? Select language »
>   English
    Enter custom
    Abkhaz
    Afar
    Afrikaans
    Akan
    Albanian
    Amharic
    Arabic
  ↓ Aragonese
√ Select language » Enter custom
? Enter custom language code »
√ Select language » Enter custom
√ Enter custom language code ... en-US
√ html5-boilerplate@latest copied to D:\projects\create-html5-boilerplate\out\vlad in 1.62 seconds . Have fun!

Result (index.html):

<!doctype html>
<html class="no-js" lang="en-US">

@roblarsen
Copy link
Member

That interface looks okay to me. How do we run and test this locally? I know you mentioned it before, but I've lost track of where

@coliff
Copy link
Member

coliff commented Jun 10, 2020

I just had a quick look - I think the interface is good also. One request though, if possible, it'd be good at the 'Select language' option to be able to type 'de' to show 'German'... as in the search results included the language code as well as the language name.

If it's not easily possible then no problem, just thought it might be useful. I do a lot of work on localisation of sites so am more familiar in using the language codes rather than typing in the language name, :-)

@coliff
Copy link
Member

coliff commented Jun 10, 2020

Also / or, if search results had language code in brackets after the language name - that'd be helpful!
Eg.

English (en)
Abkhazian (ab)
Afar (aa)
Afrikaans (af)
Akan (ak)
......

@vltansky
Copy link
Member Author

@coliff looks good?

? Select language » de
>   German (de)
    Greek, Modern (el)
    Hebrew (modern) (he)
    North Ndebele (nd)
    South Ndebele (nr)
    Divehi; Dhivehi; Maldivian; (dv)
    Indonesian (id)
    Sundanese (su)
    Tibetan Standard, Tibetan, Central (bo)
  ↓ Venda (ve)

@roblarsen you can git clone this branch and run npm link, then npm will use it as a global node module.
I'll write some tests for this today/tomorrow and then it will be ready for merge.

@lgtm-com
Copy link

lgtm-com bot commented Jun 11, 2020

This pull request introduces 1 alert when merging b52b92c into 0b00f9f - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@coliff
Copy link
Member

coliff commented Jun 11, 2020

@vltansky great work! I just tested your latest update and it looks great. I can now type de to get German and having the language code in brackets after the name is helpful. 👍

@vltansky
Copy link
Member Author

Ok, it's done and ready for merge as for me.
But there is a few extra I'd want to share:

  1. I've added the argument --yes (alias -y) as you have in npm init -y to skip prompts and go with the default choices. (default lang is lang="" - empty)
  2. Argument --lang= (without alias) to pass lang value as an argument and to skip prompt. Example npm init html5-boilerplate --lang=en-US.
  3. I do not know how to test prompts. That one of the reasons why I added --lang, I wrote tests for the lang functionality, but not for the prompt. I marked prompt code sections with istanbul ignore.

@vltansky vltansky marked this pull request as ready for review June 11, 2020 14:57
Copy link
Member

@roblarsen roblarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Let's get this merged. We just need to resolve the conflict.

@roblarsen roblarsen added this to the 0.2.0 milestone Jun 12, 2020
@vltansky
Copy link
Member Author

Done :)

@vltansky
Copy link
Member Author

@roblarsen can we merge this?

@roblarsen roblarsen merged commit e3dfaba into h5bp:master Jun 12, 2020
@roblarsen
Copy link
Member

done!

@vltansky vltansky mentioned this pull request Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants