Skip to content

Commit

Permalink
[i18PP-281] Static data updation for country (IN) (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzp-Piyush authored Nov 29, 2024
1 parent 01188b3 commit 495c7e0
Show file tree
Hide file tree
Showing 4 changed files with 27,226 additions and 57,024 deletions.
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

0 comments on commit 495c7e0

Please sign in to comment.