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

i18nify-go geo sdk #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage
/playwright-report/
/blob-report/
/playwright/.cache/
.idea/
**/.idea/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ Unleash the power of **i18nify-js**, the heart of all things i18nify. Its README
[i18nify-react docs](https://github.com/razorpay/i18nify/blob/master/packages/i18nify-react/README.md)

Built as a wrapper over i18nify-js, **i18nify-react** simplifies the integration with React. Explore its README for seamless installation, API documentation, and additional features tailored for the React library.

### Go SDK:

Convert json to json schema
1. quicktype data/<attribute>_v1.json -l schema -o data/schema/<attribute>_schema.json


2. quicktype -s schema data/schema/<attribute>_schema.json -o generator/go/<attribute>.go
3. mkdir -p packages/i18nify-go/modules/<attribute> && cp -R generator/go/<attribute>.go packages/i18nify-go/modules/<attribute>
4.
34 changes: 34 additions & 0 deletions data/country_v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"country_information": {
"MY": {
"country_name": "Malaysia",
"continent_name": "Asia",
"continent_code": "AS",
"subdivisions_1": {
"Kedah": {
"sub_division_1_name": "Kedah",
"pincode" : [56767, 56768]
}
}
},
"IN": {
"country_name": "India",
"continent_name": "Asia",
"continent_code": "AS",
"subdivisions_1": {
"KA": {
"sub_division_1_name": "Karnataka",
"pincode" : [222222, 222223]
},
"TN": {
"sub_division_1_name": "Tamil Nadu",
"pincode" : [333333, 333334]
},
"MH": {
"sub_division_1_name": "Maharastra",
"pincode" : [111111, 111112]
}
}
}
}
}
62 changes: 62 additions & 0 deletions data/schema/country_v1_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Country3Schema",
"definitions": {
"Country3Schema": {
"type": "object",
"additionalProperties": false,
"properties": {
"country_information": {
"$ref": "#/definitions/CountryInformation"
}
},
"required": [
"country_information"
],
"title": "Country3Schema"
},
"CountryInformation": {
"type": "object",
"additionalProperties": false,
"properties": {
"country_name": {
"type": "string"
},
"continent_name": {
"type": "string"
},
"continent_code": {
"type": "string"
},
"subdivisions_1": {
"$ref": "#/definitions/Subdivisions1"
}
},
"required": [
"country_name",
"continent_code",
"continent_name",
"subdivisions_1"
],
"title": "CountryInformation"
},
"Subdivisions1": {
"type": "object",
"additionalProperties": false,
"properties": {
"sub_division_1_name": {
"type": "string"
},
"pincode": {
"type": "array",
"items": {"type": "integer"}
}
},
"required": [
"sub_division_1_name",
"pincode"
],
"title": "Subdivisions1"
}
}
}
29 changes: 29 additions & 0 deletions packages/i18nify-go/country.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package i18nify_go

import (
"fmt"
"i18nify/packages/i18nify-go/modules/country_information"
"io/ioutil"
)

const CountryData_File = "modules/country_information/data/country_v1.json"

type CountryV1 struct {
country country_information.Country
}

func (c CountryV1) GetCountryInformation(code string) country_information.CountryInformation {
return c.country.GetCountryInformation()[code]
}

func NewCountryV1() ICountry {
jsonData, err := ioutil.ReadFile(CountryData_File)
if err != nil {
fmt.Println("Error reading JSON file:", err)
return nil
}
c, _ := country_information.UnmarshalCountry(jsonData)

v1 := CountryV1{country: c}
return v1
}
13 changes: 13 additions & 0 deletions packages/i18nify-go/example/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
i18nify_go "i18nify/packages/i18nify-go"
)

func main() {
countryV1 := i18nify_go.NewCountryV1()
fmt.Println(countryV1.GetCountryInformation("IN"))
fmt.Println(countryV1.GetCountryInformation("MY"))
fmt.Println(countryV1.GetCountryInformation("US"))
}
3 changes: 3 additions & 0 deletions packages/i18nify-go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module i18nify/packages/i18nify-go

go 1.20
9 changes: 9 additions & 0 deletions packages/i18nify-go/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package i18nify_go

import (
"i18nify/packages/i18nify-go/modules/country_information"
)

type ICountry interface {
GetCountryInformation(code string) country_information.CountryInformation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"country_information": {
"MY": {
"country_name": "Malaysia",
"continent_name": "Asia",
"continent_code": "AS",
"subdivisions_1": {
"Kedah": {
"sub_division_1_name": "Kedah",
"pincode" : [56767, 56768]
}
}
},
"IN": {
"country_name": "India",
"continent_name": "Asia",
"continent_code": "AS",
"subdivisions_1": {
"KA": {
"sub_division_1_name": "Karnataka",
"pincode" : [222222, 222223]
},
"TN": {
"sub_division_1_name": "Tamil Nadu",
"pincode" : [333333, 333334]
},
"MH": {
"sub_division_1_name": "Maharastra",
"pincode" : [111111, 111112]
}
}
}
}
}
85 changes: 85 additions & 0 deletions packages/i18nify-go/modules/country_information/stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// Country, err := UnmarshalCountry(bytes)
// bytes, err = Country.Marshal()

package country_information

import "encoding/json"

func UnmarshalCountry(data []byte) (Country, error) {
var r Country
err := json.Unmarshal(data, &r)
return r, err
}

func (r *Country) Marshal() ([]byte, error) {
return json.Marshal(r)
}

type Country struct {
CountryInformation map[string]CountryInformation `json:"country_information"`
}

func (r *Country) GetCountryInformation() map[string]CountryInformation {
return r.CountryInformation
}

func NewCountry(countryInformation map[string]CountryInformation) *Country {
return &Country{
CountryInformation: countryInformation,
}
}

type CountryInformation struct {
ContinentCode string `json:"continent_code"`
ContinentName string `json:"continent_name"`
CountryName string `json:"country_name"`
Subdivisions1 map[string]Subdivisions1 `json:"subdivisions_1"`
}

func (r *CountryInformation) GetContinentCode() string {
return r.ContinentCode
}

func (r *CountryInformation) GetContinentName() string {
return r.ContinentName
}

func (r *CountryInformation) GetCountryName() string {
return r.CountryName
}

func (r *CountryInformation) GetSubdivisions1() map[string]Subdivisions1 {
return r.Subdivisions1
}

func NewCountryInformation(continentCode string, continentName string, countryName string, subdivisions_1 map[string]Subdivisions1) *CountryInformation {
return &CountryInformation{
ContinentCode: continentCode,
ContinentName: continentName,
CountryName: countryName,
Subdivisions1: subdivisions_1,
}
}

type Subdivisions1 struct {
Pincode []int64 `json:"pincode"`
SubDivision1_Name string `json:"sub_division_1_name"`
}

func (r *Subdivisions1) GetPincode() []int64 {
return r.Pincode
}

func (r *Subdivisions1) GetSubDivision1_Name() string {
return r.SubDivision1_Name
}

func NewSubdivisions1(pincode []int64, subDivision_1Name string) *Subdivisions1 {
return &Subdivisions1{
Pincode: pincode,
SubDivision1_Name: subDivision_1Name,
}
}