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

[i18PP-281] Static data updation for country (IN) #183

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/i18nify-go/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func main() {
fmt.Println(subdivisions.GetCountryName()) //India

state := subdivisions.GetStates()["KA"]
fmt.Println(state.GetName()) //Karnataka
fmt.Println(state.GetCities()[0]) //{Yellāpur nan Asia/Kolkata [581337 581337 ...}
fmt.Println(state.GetName()) //Karnataka
fmt.Println(state.GetCities()[0]) //{Yellāpur nan Asia/Kolkata [581337 581337 ...}
fmt.Println(len(state.GetCities())) //58

//USD
currencyUS := currency.GetCurrencyInformation("USD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ func NewCountrySubdivisions(countryName string, states map[string]State) *Countr

// State contains information about a state or province.
type State struct {
Cities []City `json:"cities"` // Cities contains information about cities within the state.
Name string `json:"name"` // Name represents the name of the state.
Cities map[string]City `json:"cities"` // Cities contains information about cities within the state.
Name string `json:"name"` // Name represents the name of the state.
}

// GetCities returns information about cities within the state.
func (r *State) GetCities() []City {
return r.Cities
cities := make([]City, 0, len(r.Cities))
for _, city := range r.Cities {
cities = append(cities, city)
}
return cities
}

// GetName returns the name of the state.
Expand All @@ -86,7 +90,7 @@ func (r *State) GetName() string {
}

// NewState creates a new State instance.
func NewState(cities []City, name string) *State {
func NewState(cities map[string]City, name string) *State {
return &State{
Cities: cities,
Name: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func TestUnmarshalCountrySubdivisions(t *testing.T) {
}

func TestMarshalCountrySubdivisions(t *testing.T) {
var expectedJSON = `{"country_name": "India", "states": {"KA": {"name": "Karnataka", "cities": [{"name": "Bengaluru", "timezone": "Asia/Kolkata", "zipcodes": ["560018", "560116", "560500"], "region_name/district_name": "nan"}]}}}`
var expectedJSON = `{"country_name": "India", "states": {"KA": {"name": "Karnataka", "cities": {"Bengaluru" : {"name": "Bengaluru", "timezone": "Asia/Kolkata", "zipcodes": ["560018", "560116", "560500"], "region_name/district_name": "nan"}}}}}`

data := CountrySubdivisions{
CountryName: "India",
States: map[string]State{
"KA": {
Cities: []City{
{Name: "Bengaluru", RegionName: "nan", Timezone: "Asia/Kolkata", Zipcodes: []string{"560018", "560116", "560500"}},
Cities: map[string]City{
"Bengaluru": {Name: "Bengaluru", RegionName: "nan", Timezone: "Asia/Kolkata", Zipcodes: []string{"560018", "560116", "560500"}},
},
Name: "Karnataka",
},
Expand Down
Loading
Loading