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

language code support #81

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

DanielHilton
Copy link
Contributor

  • Adding ISO-639-1 language code support
  • Adding tests

@DanielHilton DanielHilton marked this pull request as draft November 13, 2024 18:38
Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for biter777countries ready!

Name Link
🔨 Latest commit cbbe224
🔍 Latest deploy log https://app.netlify.com/sites/biter777countries/deploys/6735ff5f79159300089d68fb
😎 Deploy Preview https://deploy-preview-81--biter777countries.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@DanielHilton
Copy link
Contributor Author

@biter777 i'd welcome your feedback on this PR! 😄

languages.go Outdated Show resolved Hide resolved
countries.go Outdated Show resolved Hide resolved
@ccoVeille
Copy link

ccoVeille commented Nov 13, 2024

One question.

Your additions are related to languages. Except the mention of the country in a few methods.

I'm unsure it should be added to this repository.

I mean you could have created your own package dedicated to languages, that is could return its own constants.

Your code is good, and highly inspired from country one. But, this repository is about countries

I'm raising the point because I find strange to add languages (another iso norm) to a repository focused on country one

@ccoVeille
Copy link

Also, have you considered existing packages available?

Here are the few I found

https://github.com/emvi/iso-639-1
https://github.com/KtorZPersonal/go-iso-codes
https://github.com/KimMachineGun/lango
https://github.com/ttab/langos
https://github.com/atadzan/langconv

Implementing methods to get the languages from a country could be addee in these packages

Comment on lines +1 to +21
package countries

import (
"encoding/json"
"fmt"
)

type LanguageCode string // string for database/sql/driver.Valuer compatibility

type Language struct {
Name string
Code LanguageCode
}

func (LanguageCode) Type() string {
return TypeLanguageCode
}

func (lc LanguageCode) String() string { //nolint:gocyclo
switch lc {
case LanguageAA:

Choose a reason for hiding this comment

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

I would move all this to a sub package

This way, it's clearer for people who imports

Also, it avoids you to prefix everything related to language with language

It would look like this

Suggested change
package countries
import (
"encoding/json"
"fmt"
)
type LanguageCode string // string for database/sql/driver.Valuer compatibility
type Language struct {
Name string
Code LanguageCode
}
func (LanguageCode) Type() string {
return TypeLanguageCode
}
func (lc LanguageCode) String() string { //nolint:gocyclo
switch lc {
case LanguageAA:
package languages
import (
"encoding/json"
"fmt"
)
type Code string // string for database/sql/driver.Valuer compatibility
type Language struct {
Name string
Code Code
}
func (Code) Type() string {
return TypeLanguageCode
}
func (lc LanguageCode) String() string { //nolint:gocyclo
switch lc {
case CodeAA:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whilst that is a fair point, that is not the way this package is written. There are other facets of a country which are all under the countries package.

Choose a reason for hiding this comment

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

You are right. Currencies are aside countries while it's another iso norm

@DanielHilton
Copy link
Contributor Author

DanielHilton commented Nov 13, 2024

One question.

Your additions are related to languages. Except the mention of the country in a few methods.

I'm unsure it should be added to this repository.

I mean you could have created your own package dedicated to languages, that is could return its own constants.

Your code is good, and highly inspired from country one. But, this repository is about countries

I'm raising the point because I find strange to add languages (another iso norm) to a repository focused on country one

This repo concerns itself with facets or properties of countries. This includes TLDs, dialing codes, regions and more. It stands to reason that when dealing with countries, it may be of use to include the language information about the country you are working with. This is not merely an ISO standard repo, as such I think it is relevant to be able to call countries.Switzerland.Languages() and be able to get LanguageGerman and LanguageFrench as an answer. This can help with localisation without relying on multiple libraries and patterns associated with each, or interop between one package and another.

@ccoVeille
Copy link

Please note, I'm not against the addition.

I raised a point to make sure and you replied

I like your PR.

@@ -181,6 +181,7 @@ const (
LanguageTatar LanguageCode = "tt"
LanguageTwi LanguageCode = "tw"
LanguageTahitian LanguageCode = "ty"
LanguageTuvaluan LanguageCode = "tvl"

Choose a reason for hiding this comment

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

tvl is not available as an iso-code in iso 639-1, only in iso 639-2 alpha-3

You shouldn't mention here, or use 3 letter code everywhere (better option)

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.

2 participants