Skip to content

Commit

Permalink
patch v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
metalwolf committed Aug 31, 2023
1 parent b716725 commit 35363ae
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 23 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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().
Expand Down
15 changes: 9 additions & 6 deletions v2/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
18 changes: 14 additions & 4 deletions v2/xcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
//
// <?xml version="1.0" encoding="UTF-8"?>
// <language id="NAMEOFTABLE" lang="LG">
// <entry id="ENTRYNAME">ENTRYVALUE</entry>
// <entry id="ENTRYNAME">ENTRYVALUE</entry>
// <entry id="ENTRYNAME" status="STATUSVALUE">ENTRYVALUE</entry>
// <entry id="ENTRYNAME" status="STATUSVALUE">ENTRYVALUE</entry>
// etc.
// </language>
//
Expand All @@ -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
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
//
//
Expand Down Expand Up @@ -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.
Expand Down
49 changes: 42 additions & 7 deletions v2/xlanguage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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, " <entry id=\""+key+"\" status=\""+l.status[key]+"\"><![CDATA["+val+"]]></entry>")
}
sort.Strings(sdata) // Lets be sure the print is always the same presentation
return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<language id=\"" + l.Name + "\" lang=\"" + fmt.Sprint(l.Language) + "\">\n" +
strings.Join(sdata, "\n") + "\n</language>"
}

// String will transform the XDataset into a readable string for humans
func (l *XLanguage) String() string {
sdata := []string{}
Expand Down
3 changes: 3 additions & 0 deletions v2/xlanguage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 35363ae

Please sign in to comment.