diff --git a/README.md b/README.md index 105c4c1..7602364 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,18 @@ +XCore for GO v2 +============================= + +# Please use xcore/v2 + +# The version 1 is obsolete. + [![Go Report Card](https://goreportcard.com/badge/github.com/webability-go/xcore)](https://goreportcard.com/report/github.com/webability-go/xcore) [![GoDoc](https://godoc.org/github.com/webability-go/xcore/v2?status.png)](https://godoc.org/github.com/webability-go/xcore/v2) [![GolangCI](https://golangci.com/badges/github.com/webability-go/xcore.svg)](https://golangci.com) -XCore for GO v2 -============================= - # Please use xcore/v2 +# The version 1 is obsolete. + import "github.com/webability-go/xcore/v2" The XCore package is used to build basic object for programmation. for the WebAbility compatility code @@ -18,14 +24,13 @@ For GO, the actual existing code includes: Manuals are available on godoc.org [![GoDoc](https://godoc.org/github.com/webability-go/xcore/v2?status.png)](https://godoc.org/github.com/webability-go/xcore/v2) -# The version 1 is obsolete. +# Please use xcore/v2 +# The version 1 is obsolete. Version Changes Control ======================= -# Please use xcore/v2 - v1.1.1 - 2022-09-02 ----------------------- - Bug corrected on XDataset.GetString() and XDatasetCollection.GetDataString(). diff --git a/v2/README.md b/v2/README.md index b6922f7..4e5accc 100644 --- a/v2/README.md +++ b/v2/README.md @@ -1,12 +1,10 @@ -@UTF-8 +XCore v2 for GO +============================= [![Go Report Card](https://goreportcard.com/badge/github.com/webability-go/xcore)](https://goreportcard.com/report/github.com/webability-go/xcore) [![GoDoc](https://godoc.org/github.com/webability-go/xcore/v2?status.png)](https://godoc.org/github.com/webability-go/xcore/v2) [![GolangCI](https://golangci.com/badges/github.com/webability-go/xcore.svg)](https://golangci.com) -XCore for GO v2 -============================= - Minimum version of GO: 1.17 (for time.Time compatibility) The XCore package is used to build basic object for programmation. for the WebAbility compatility code @@ -19,8 +17,8 @@ For GO, the actual existing code includes: Manuals are available on godoc.org [![GoDoc](https://godoc.org/github.com/webability-go/xcore?status.png)](https://godoc.org/github.com/webability-go/xcore) -TO DO: -====== +TO DO, maybe: +============= - XDataset.Set should accept path too > > > - Get*Collection should convert types too - XTemplate must concatenate strings after compilation @@ -33,6 +31,11 @@ Some improvements to check, later: Version Changes Control ======================= +v2.2.0 - 2023-08-31 +----------------------- +- Added the parameter status to xlanguage XML and function to get/set the parameter. +- Added the function GetXML() to marshal the structure to an XML file. + v2.1.7 - 2023-06-15 ----------------------- - Added the missing counter for @@ meta language. Using {{.counter}} into the loop template, you can add the number of the dataset, 1-based. diff --git a/v2/xcore.go b/v2/xcore.go index 2f3589f..8371ec9 100644 --- a/v2/xcore.go +++ b/v2/xcore.go @@ -132,8 +132,8 @@ // // // -// ENTRYVALUE -// ENTRYVALUE +// ENTRYVALUE +// ENTRYVALUE // etc. // // @@ -145,6 +145,9 @@ // // ENTRYVALUE is the text for your entry, for example "Hello", "You are:", "Save" if your table is in english. // +// STATUSVALUE is the status of the entry- You may put any value to control your translation over time and processes. +// +// // 1.2 The flat text format is: // // ENTRYNAME=ENTRYVALUE @@ -179,6 +182,14 @@ // SetName/SetLanguage functions are used to set the table name and language of the object (generally to build an object from scratch). // GetName/GetLanguage functions are used to get the table name and language of the object (generally when you load it from some source). // Set/Get/Del functions are used to add or modify a new entry, read an entry, or deletes an entry in the object. +// SetStatus/GetStatus functions are used to add or get a status for the entry in the object. +// +// To create am XML file from the objet, you can use the GetXML() function +// +// langfromxmlfile := NewXLanguageFromXMLFile("path/to/filename") +// str := langfromxmlfile.GetXML() +// +// // // XDataSet // @@ -306,7 +317,6 @@ // datats := xcore.NewXDatasetTS(datanots) // // Note that all references to XDatasetTS are pointers, always (to be able to modify the values of them). -// // The DatasetTS meet the XDatasetDef interface // // @@ -869,7 +879,7 @@ package xcore // VERSION is the used version nombre of the XCore library. -const VERSION = "2.1.7" +const VERSION = "2.2.0" // LOG is the flag to activate logging on the library. // if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters. diff --git a/v2/xlanguage.go b/v2/xlanguage.go index dc843a9..67d3b95 100644 --- a/v2/xlanguage.go +++ b/v2/xlanguage.go @@ -18,18 +18,19 @@ type XLanguage struct { Name string Language language.Tag entries map[string]string + status map[string]string mutex sync.RWMutex } // NewXLanguage will create an empty Language structure with a name and a language func NewXLanguage(name string, lang language.Tag) *XLanguage { - return &XLanguage{Name: name, Language: lang, entries: make(map[string]string)} + return &XLanguage{Name: name, Language: lang, entries: make(map[string]string), status: make(map[string]string)} } // NewXLanguageFromXMLFile will create an XLanguage structure with the data into the XML file // Returns nil if there is an error func NewXLanguageFromXMLFile(file string) (*XLanguage, error) { - lang := &XLanguage{entries: make(map[string]string)} + lang := &XLanguage{entries: make(map[string]string), status: make(map[string]string)} err := lang.LoadXMLFile(file) if err != nil { return nil, err @@ -40,7 +41,7 @@ func NewXLanguageFromXMLFile(file string) (*XLanguage, error) { // NewXLanguageFromXMLString will create an XLanguage structure with the data into the XML String // Returns nil if there is an error func NewXLanguageFromXMLString(xml string) (*XLanguage, error) { - lang := &XLanguage{entries: make(map[string]string)} + lang := &XLanguage{entries: make(map[string]string), status: make(map[string]string)} err := lang.LoadXMLString(xml) if err != nil { return nil, err @@ -51,7 +52,7 @@ func NewXLanguageFromXMLString(xml string) (*XLanguage, error) { // NewXLanguageFromFile will create an XLanguage structure with the data into the text file // Returns nil if there is an error func NewXLanguageFromFile(file string) (*XLanguage, error) { - l := &XLanguage{entries: make(map[string]string)} + l := &XLanguage{entries: make(map[string]string), status: make(map[string]string)} err := l.LoadFile(file) if err != nil { return nil, err @@ -62,7 +63,7 @@ func NewXLanguageFromFile(file string) (*XLanguage, error) { // NewXLanguageFromString will create an XLanguage structure with the data into the string // Returns nil if there is an error func NewXLanguageFromString(data string) (*XLanguage, error) { - l := &XLanguage{entries: make(map[string]string)} + l := &XLanguage{entries: make(map[string]string), status: make(map[string]string)} err := l.LoadString(data) if err != nil { return nil, err @@ -85,8 +86,9 @@ func (l *XLanguage) LoadXMLFile(file string) error { func (l *XLanguage) LoadXMLString(data string) error { // Temporal structures for XML loading type xentry struct { - ID string `xml:"id,attr"` - Entry string `xml:",chardata"` + ID string `xml:"id,attr"` + Entry string `xml:",chardata"` + Status string `xml:"status,attr"` } type xlang struct { @@ -110,6 +112,7 @@ func (l *XLanguage) LoadXMLString(data string) error { defer l.mutex.Unlock() for _, e := range temp.Entries { l.entries[e.ID] = e.Entry + l.status[e.ID] = e.Status } return nil } @@ -204,11 +207,30 @@ func (l *XLanguage) Get(entry string) string { return "" } +// Set will add an entry id-value into the language table +func (l *XLanguage) SetStatus(entry string, value string) { + l.mutex.Lock() + defer l.mutex.Unlock() + l.status[entry] = value +} + +// Get will read an entry id-value from the language table +func (l *XLanguage) GetStatus(entry string) string { + l.mutex.RLock() + defer l.mutex.RUnlock() + v, ok := l.status[entry] + if ok { + return v + } + return "" +} + // Del will remove an entry id-value from the language table func (l *XLanguage) Del(entry string) { l.mutex.Lock() defer l.mutex.Unlock() delete(l.entries, entry) + delete(l.status, entry) } // GetEntries will return a COPY of the key-values pairs of the language. @@ -222,6 +244,19 @@ func (l *XLanguage) GetEntries() map[string]string { return clone } +// GetXML will generate the XML to save the file +func (l *XLanguage) GetXML() string { + sdata := []string{} + l.mutex.RLock() + defer l.mutex.RUnlock() + for key, val := range l.entries { + sdata = append(sdata, " ") + } + sort.Strings(sdata) // Lets be sure the print is always the same presentation + return "\n\n" + + strings.Join(sdata, "\n") + "\n" +} + // String will transform the XDataset into a readable string for humans func (l *XLanguage) String() string { sdata := []string{} diff --git a/v2/xlanguage_test.go b/v2/xlanguage_test.go index f5797cb..4b635d5 100644 --- a/v2/xlanguage_test.go +++ b/v2/xlanguage_test.go @@ -202,4 +202,7 @@ func TestXLanguageAssign(t *testing.T) { t.Errorf("The print #value language is not correct %s", str) return } + + str = manualES.GetXML() + fmt.Println(str) }