Skip to content

Commit

Permalink
- v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinetwigs committed Jun 11, 2022
1 parent db805c1 commit 925c204
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
main.go
strings/strings.xml
strings
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2022-06-11

### Added

- Support for [JSON file format](https://www.json.org/json-en.html)
- Support for [YAML file format](https://yaml.org/)
- Support for [TOML file format](https://toml.io/en/)
- Support for [WATSON file format](https://github.com/genkami/watson)

- SetResourceType function

- FileType enum

### Changed

- CreateXMLFile function is now CreateResourceFile and takes a FileType parameter
- DeleteResourceFile function is now DeleteResourceFile
- LoadValues function now takes a FileType parameter

## [1.1.0] - 2022-06-06

### Added

- Support for XML file format

- CreateXMLFile, DeleteXMLFile, LoadValues, NewString, NewStringArray, NewQuantityString, SetFewThreshold, GetString, GetStringArray, GetQuantityString functions
103 changes: 74 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,39 @@
</i>
</p>

## Table of Contents
## Table of contents

* [References](#references)
* [Prerequisites](#prerequisites)
* [Installing](#installing)
+ [Install module](#install-module)
+ [Import in your project](#import-in-your-project)
- [Documentation](#documentation)
* [Types](#types)
+ [Plural](#plural)
+ [PluralItem](#pluralitem)
+ [Item](#item)
+ [StringArray](#stringarray)
+ [String](#string)
+ [Nesting](#nesting)
* [CreateResourceFile](#createresourcefile)
* [DeleteResourceFile](#deleteresourcefile)
* [LoadValues](#loadvalues)
* [SetResourceType](#setresourcetype)
* [NewString](#newstring)
* [NewStringArray](#newstringarray)
* [NewQuantityString](#newquantitystring)
* [SetFewThreshold](#setfewthreshold)
* [GetString](#getstring)
* [GetArrayString](#getarraystring)
* [GetQuantityString](#getquantitystring)
- [Contributors](#contributors)

[TOC]

### References

* [Android Studio string resources](https://developer.android.com/guide/topics/resources/string-resource)
* [CHANGELOG](./CHANGELOG.md)

[Back to top](#table-of-contents)

Expand Down Expand Up @@ -53,9 +79,9 @@ import("github.com/Vinetwigs/stres")

```go
type Plural struct {
XMLName xml.Name `xml:"plurals"`
Name string `xml:"name,attr"`
Items []*PluralItem `xml:"item"`
XMLName xml.Name `xml:"plurals" json:"plurals" yaml:"plurals" toml:"plurals" watson:"plurals"`
Name string `xml:"name,attr" json:"name" yaml:"name" toml:"name" watson:"name"`
Items []*PluralItem `xml:"item" json:"items" yaml:"items,flow" toml:"items,multiline" watson:"items"`
}
```

Expand All @@ -65,9 +91,9 @@ type Plural struct {

```go
type PluralItem struct {
XMLName xml.Name `xml:"item"`
Quantity string `xml:"quantity,attr"`
Value string `xml:",innerxml"`
XMLName xml.Name `xml:"item" json:"item" yaml:"item" toml:"item" watson:"item"`
Quantity string `xml:"quantity,attr" json:"quantity" yaml:"quantity" toml:"quantity" watson:"quantity"`
Value string `xml:",innerxml" json:"value" yaml:"value" toml:"value" watson:"value"`
}
```

Expand All @@ -77,8 +103,8 @@ type PluralItem struct {

```go
type Item struct {
XMLName xml.Name `xml:"item"`
Value string `xml:",innerxml"`
XMLName xml.Name `xml:"item" json:"item" yaml:"item" toml:"item" watson:"item"`
Value string `xml:",innerxml" json:"value" yaml:"value" toml:"value" watson:"value"`
}
```

Expand All @@ -88,9 +114,9 @@ type Item struct {

```go
type StringArray struct {
XMLName xml.Name `xml:"string-array"`
Name string `xml:"name,attr"`
Items []*Item `xml:"item"`
XMLName xml.Name `xml:"string-array" json:"string-array" yaml:"string-array" toml:"string-array" watson:"string-array"`
Name string `xml:"name,attr" json:"name" yaml:"name" toml:"name" watson:"name"`
Items []*Item `xml:"item" json:"items" yaml:"items,flow" toml:"items,multiline" watson:"items"`
}
```

Expand All @@ -100,9 +126,9 @@ type StringArray struct {

```go
type String struct {
XMLName xml.Name `xml:"string"`
Name string `xml:"name,attr"`
Value string `xml:",innerxml"`
XMLName xml.Name `xml:"string" json:"string" yaml:"string" toml:"string" watson:"string"`
Name string `xml:"name,attr" json:"name" yaml:"name" toml:"name" watson:"name"`
Value string `xml:",innerxml" json:"value" yaml:"value" toml:"value" watson:"value"`
}
```

Expand All @@ -112,38 +138,57 @@ type String struct {

```go
type Nesting struct {
XMLName xml.Name `xml:"resources"`
Strings []*String `xml:"string"`
StringsArray []*StringArray `xml:"string-array"`
Plurals []*Plural `xml:"plurals"`
XMLName xml.Name `xml:"resources" json:"resources" yaml:"resources" toml:"resources" watson:"resources"`
Strings []*String `xml:"string" json:"string" yaml:"string,flow" toml:"string,multiline" watson:"string"`
StringsArray []*StringArray `xml:"string-array" json:"string-array" yaml:"string-array,flow" toml:"string-array,multiline" watson:"string-array"`
Plurals []*Plural `xml:"plurals" json:"plurals" yaml:"plurals,flow" toml:"plurals,multiline" watson:"plurals"`
}
```

[Back to top](#table-of-contents)

### CreateXMLFile
*Creates strings.xml file in "strings" directory, throws an error otherwise.*
### CreateResourceFile
*Creates strings resource file in "strings" directory, throws an error otherwise. Takes a FileType parameter to specify strings file format.*

`file, err := stres.CreateXMLFile()`
`file, err := stres.CreateXMLFile()`

| Parameter | Type | Description |
|-----------|--------|---------------------------------------|
| t | types.FileType | enum value to specify file format |

[Back to top](#table-of-contents)

### DeleteXMLFile
*Deletes XML file if exists, throws an error otherwise.*
### DeleteResourceFile
*Deletes resource file if exists, throws an error otherwise. Uses setted resource file extension.*

`err := stres.DeleteXMLFile()`

[Back to top](#table-of-contents)

### LoadValues
*Loads values from strings.xml file into internal dictionaries. Needs to be invoked only one time (but before getting strings values).*
*Loads values from strings file into internal dictionaries. Needs to be invoked only one time (but before getting strings values).Takes a FileType parameter to specify strings file format.*

`err := stres.LoadValues()`

[Back to top](#table-of-contents)

| Parameter | Type | Description |
|-----------|--------|---------------------------------------|
| t | types.FileType | enum value to specify file format |

### SetResourceType
*Used to specify string file extension. If t is a wrong FileType, sets resource type to XML by default.*

`stres.SetResourceType(stres.WATSON)`

| Parameter | Type | Description |
|-----------|--------|---------------------------------------|
| t | types.FileType | enum value to specify file format |

[Back to top](#table-of-contents)

### NewString
*Adds a new string resource to XML file. Throws an error if the chosen name is already inserted or it is an empty string. Used for programmatic insertion (manual insertion recommended).*
*Adds a new string resource to resource file. Throws an error if the chosen name is already inserted or it is an empty string. Used for programmatic insertion (manual insertion recommended).*

`String, err := stres.NewString("name", "value")`

Expand All @@ -158,7 +203,7 @@ Returns String instance and error.
[Back to top](#table-of-contents)

### NewStringArray
*Adds a new string-array resource to XML file. Throws an error if the chosen name is already inserted or it is an empty string. Used for programmatic insertion (manual insertion recommended).*
*Adds a new string-array resource to resource file. Throws an error if the chosen name is already inserted or it is an empty string. Used for programmatic insertion (manual insertion recommended).*

`strArr, err := stres.NewStringArray("name", []string{"value1","value2",...})`

Expand All @@ -172,7 +217,7 @@ Returns StringArray instance and error.
[Back to top](#table-of-contents)

### NewQuantityString
*Adds a new quantity string resource to XML file. Throws an error if the chosen name is already inserted or it is an empty string. The function uses only the first 5 values in the array. The first value is assigned to "zero" quantity. The second value is assigned to "one" quantity. The third value is assigned to "two" quantity. The fourth value is assigned to "few" quantity. The fifth value is assigned to "more" quantity. Used for programmatic insertion (manual insertion recommended).*
*Adds a new quantity string resource to resource file. Throws an error if the chosen name is already inserted or it is an empty string. The function uses only the first 5 values in the array. The first value is assigned to "zero" quantity. The second value is assigned to "one" quantity. The third value is assigned to "two" quantity. The fourth value is assigned to "few" quantity. The fifth value is assigned to "more" quantity. Used for programmatic insertion (manual insertion recommended).*

`qntStr, err := stres.NewQuantityString("name", []string{"zero","one", "two", ...})`

Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module github.com/Vinetwigs/stres

go 1.17

require gopkg.in/yaml.v3 v3.0.1

require github.com/pelletier/go-toml/v2 v2.0.2

require github.com/genkami/watson v1.0.0
25 changes: 25 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/genkami/watson v1.0.0 h1:wnitYUtaR8GWNQhvJ/VCoqOrC12iRRvtWlff9IKVJmI=
github.com/genkami/watson v1.0.0/go.mod h1:h0pRN42xxvCHX/Oyopf4AxtAv4z0+51qRN+K6UxF70g=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pelletier/go-toml/v2 v2.0.2 h1:+jQXlF3scKIcSEKkdHzXhCTDLPFi5r1wnK6yPS+49Gw=
github.com/pelletier/go-toml/v2 v2.0.2/go.mod h1:MovirKjgVRESsAvNZlAjtFwV867yGuwRkXbG66OzopI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/vmihailenco/msgpack/v5 v5.2.0/go.mod h1:fEM7KuHcnm0GvDCztRpw9hV0PuoO2ciTismP6vjggcM=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 925c204

Please sign in to comment.