Skip to content

Commit 9a8fdf5

Browse files
authored
Merge pull request #75 from webability-go/late-night
patch v2.2.0
2 parents e2a566a + 35363ae commit 9a8fdf5

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
XCore for GO v2
2+
=============================
3+
4+
# Please use xcore/v2
5+
6+
# The version 1 is obsolete.
7+
18
[![Go Report Card](https://goreportcard.com/badge/github.com/webability-go/xcore)](https://goreportcard.com/report/github.com/webability-go/xcore)
29
[![GoDoc](https://godoc.org/github.com/webability-go/xcore/v2?status.png)](https://godoc.org/github.com/webability-go/xcore/v2)
310
[![GolangCI](https://golangci.com/badges/github.com/webability-go/xcore.svg)](https://golangci.com)
411

5-
XCore for GO v2
6-
=============================
7-
812
# Please use xcore/v2
913

14+
# The version 1 is obsolete.
15+
1016
import "github.com/webability-go/xcore/v2"
1117

1218
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:
1824

1925
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)
2026

21-
# The version 1 is obsolete.
27+
# Please use xcore/v2
2228

29+
# The version 1 is obsolete.
2330

2431
Version Changes Control
2532
=======================
2633

27-
# Please use xcore/v2
28-
2934
v1.1.1 - 2022-09-02
3035
-----------------------
3136
- Bug corrected on XDataset.GetString() and XDatasetCollection.GetDataString().

v2/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
@UTF-8
1+
XCore v2 for GO
2+
=============================
23

34
[![Go Report Card](https://goreportcard.com/badge/github.com/webability-go/xcore)](https://goreportcard.com/report/github.com/webability-go/xcore)
45
[![GoDoc](https://godoc.org/github.com/webability-go/xcore/v2?status.png)](https://godoc.org/github.com/webability-go/xcore/v2)
56
[![GolangCI](https://golangci.com/badges/github.com/webability-go/xcore.svg)](https://golangci.com)
67

7-
XCore for GO v2
8-
=============================
9-
108
Minimum version of GO: 1.17 (for time.Time compatibility)
119

1210
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:
1917
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)
2018

2119

22-
TO DO:
23-
======
20+
TO DO, maybe:
21+
=============
2422
- XDataset.Set should accept path too > > >
2523
- Get*Collection should convert types too
2624
- XTemplate must concatenate strings after compilation
@@ -33,6 +31,11 @@ Some improvements to check, later:
3331
Version Changes Control
3432
=======================
3533

34+
v2.2.0 - 2023-08-31
35+
-----------------------
36+
- Added the parameter status to xlanguage XML and function to get/set the parameter.
37+
- Added the function GetXML() to marshal the structure to an XML file.
38+
3639
v2.1.7 - 2023-06-15
3740
-----------------------
3841
- Added the missing counter for @@ meta language. Using {{.counter}} into the loop template, you can add the number of the dataset, 1-based.

v2/xcore.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@
132132
//
133133
// <?xml version="1.0" encoding="UTF-8"?>
134134
// <language id="NAMEOFTABLE" lang="LG">
135-
// <entry id="ENTRYNAME">ENTRYVALUE</entry>
136-
// <entry id="ENTRYNAME">ENTRYVALUE</entry>
135+
// <entry id="ENTRYNAME" status="STATUSVALUE">ENTRYVALUE</entry>
136+
// <entry id="ENTRYNAME" status="STATUSVALUE">ENTRYVALUE</entry>
137137
// etc.
138138
// </language>
139139
//
@@ -145,6 +145,9 @@
145145
//
146146
// ENTRYVALUE is the text for your entry, for example "Hello", "You are:", "Save" if your table is in english.
147147
//
148+
// STATUSVALUE is the status of the entry- You may put any value to control your translation over time and processes.
149+
//
150+
//
148151
// 1.2 The flat text format is:
149152
//
150153
// ENTRYNAME=ENTRYVALUE
@@ -179,6 +182,14 @@
179182
// SetName/SetLanguage functions are used to set the table name and language of the object (generally to build an object from scratch).
180183
// GetName/GetLanguage functions are used to get the table name and language of the object (generally when you load it from some source).
181184
// Set/Get/Del functions are used to add or modify a new entry, read an entry, or deletes an entry in the object.
185+
// SetStatus/GetStatus functions are used to add or get a status for the entry in the object.
186+
//
187+
// To create am XML file from the objet, you can use the GetXML() function
188+
//
189+
// langfromxmlfile := NewXLanguageFromXMLFile("path/to/filename")
190+
// str := langfromxmlfile.GetXML()
191+
//
192+
//
182193
//
183194
// XDataSet
184195
//
@@ -306,7 +317,6 @@
306317
// datats := xcore.NewXDatasetTS(datanots)
307318
//
308319
// Note that all references to XDatasetTS are pointers, always (to be able to modify the values of them).
309-
//
310320
// The DatasetTS meet the XDatasetDef interface
311321
//
312322
//
@@ -869,7 +879,7 @@
869879
package xcore
870880

871881
// VERSION is the used version nombre of the XCore library.
872-
const VERSION = "2.1.7"
882+
const VERSION = "2.2.0"
873883

874884
// LOG is the flag to activate logging on the library.
875885
// if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters.

v2/xlanguage.go

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ type XLanguage struct {
1818
Name string
1919
Language language.Tag
2020
entries map[string]string
21+
status map[string]string
2122
mutex sync.RWMutex
2223
}
2324

2425
// NewXLanguage will create an empty Language structure with a name and a language
2526
func NewXLanguage(name string, lang language.Tag) *XLanguage {
26-
return &XLanguage{Name: name, Language: lang, entries: make(map[string]string)}
27+
return &XLanguage{Name: name, Language: lang, entries: make(map[string]string), status: make(map[string]string)}
2728
}
2829

2930
// NewXLanguageFromXMLFile will create an XLanguage structure with the data into the XML file
3031
// Returns nil if there is an error
3132
func NewXLanguageFromXMLFile(file string) (*XLanguage, error) {
32-
lang := &XLanguage{entries: make(map[string]string)}
33+
lang := &XLanguage{entries: make(map[string]string), status: make(map[string]string)}
3334
err := lang.LoadXMLFile(file)
3435
if err != nil {
3536
return nil, err
@@ -40,7 +41,7 @@ func NewXLanguageFromXMLFile(file string) (*XLanguage, error) {
4041
// NewXLanguageFromXMLString will create an XLanguage structure with the data into the XML String
4142
// Returns nil if there is an error
4243
func NewXLanguageFromXMLString(xml string) (*XLanguage, error) {
43-
lang := &XLanguage{entries: make(map[string]string)}
44+
lang := &XLanguage{entries: make(map[string]string), status: make(map[string]string)}
4445
err := lang.LoadXMLString(xml)
4546
if err != nil {
4647
return nil, err
@@ -51,7 +52,7 @@ func NewXLanguageFromXMLString(xml string) (*XLanguage, error) {
5152
// NewXLanguageFromFile will create an XLanguage structure with the data into the text file
5253
// Returns nil if there is an error
5354
func NewXLanguageFromFile(file string) (*XLanguage, error) {
54-
l := &XLanguage{entries: make(map[string]string)}
55+
l := &XLanguage{entries: make(map[string]string), status: make(map[string]string)}
5556
err := l.LoadFile(file)
5657
if err != nil {
5758
return nil, err
@@ -62,7 +63,7 @@ func NewXLanguageFromFile(file string) (*XLanguage, error) {
6263
// NewXLanguageFromString will create an XLanguage structure with the data into the string
6364
// Returns nil if there is an error
6465
func NewXLanguageFromString(data string) (*XLanguage, error) {
65-
l := &XLanguage{entries: make(map[string]string)}
66+
l := &XLanguage{entries: make(map[string]string), status: make(map[string]string)}
6667
err := l.LoadString(data)
6768
if err != nil {
6869
return nil, err
@@ -85,8 +86,9 @@ func (l *XLanguage) LoadXMLFile(file string) error {
8586
func (l *XLanguage) LoadXMLString(data string) error {
8687
// Temporal structures for XML loading
8788
type xentry struct {
88-
ID string `xml:"id,attr"`
89-
Entry string `xml:",chardata"`
89+
ID string `xml:"id,attr"`
90+
Entry string `xml:",chardata"`
91+
Status string `xml:"status,attr"`
9092
}
9193

9294
type xlang struct {
@@ -110,6 +112,7 @@ func (l *XLanguage) LoadXMLString(data string) error {
110112
defer l.mutex.Unlock()
111113
for _, e := range temp.Entries {
112114
l.entries[e.ID] = e.Entry
115+
l.status[e.ID] = e.Status
113116
}
114117
return nil
115118
}
@@ -204,11 +207,30 @@ func (l *XLanguage) Get(entry string) string {
204207
return ""
205208
}
206209

210+
// Set will add an entry id-value into the language table
211+
func (l *XLanguage) SetStatus(entry string, value string) {
212+
l.mutex.Lock()
213+
defer l.mutex.Unlock()
214+
l.status[entry] = value
215+
}
216+
217+
// Get will read an entry id-value from the language table
218+
func (l *XLanguage) GetStatus(entry string) string {
219+
l.mutex.RLock()
220+
defer l.mutex.RUnlock()
221+
v, ok := l.status[entry]
222+
if ok {
223+
return v
224+
}
225+
return ""
226+
}
227+
207228
// Del will remove an entry id-value from the language table
208229
func (l *XLanguage) Del(entry string) {
209230
l.mutex.Lock()
210231
defer l.mutex.Unlock()
211232
delete(l.entries, entry)
233+
delete(l.status, entry)
212234
}
213235

214236
// GetEntries will return a COPY of the key-values pairs of the language.
@@ -222,6 +244,19 @@ func (l *XLanguage) GetEntries() map[string]string {
222244
return clone
223245
}
224246

247+
// GetXML will generate the XML to save the file
248+
func (l *XLanguage) GetXML() string {
249+
sdata := []string{}
250+
l.mutex.RLock()
251+
defer l.mutex.RUnlock()
252+
for key, val := range l.entries {
253+
sdata = append(sdata, " <entry id=\""+key+"\" status=\""+l.status[key]+"\"><![CDATA["+val+"]]></entry>")
254+
}
255+
sort.Strings(sdata) // Lets be sure the print is always the same presentation
256+
return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<language id=\"" + l.Name + "\" lang=\"" + fmt.Sprint(l.Language) + "\">\n" +
257+
strings.Join(sdata, "\n") + "\n</language>"
258+
}
259+
225260
// String will transform the XDataset into a readable string for humans
226261
func (l *XLanguage) String() string {
227262
sdata := []string{}

v2/xlanguage_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,7 @@ func TestXLanguageAssign(t *testing.T) {
202202
t.Errorf("The print #value language is not correct %s", str)
203203
return
204204
}
205+
206+
str = manualES.GetXML()
207+
fmt.Println(str)
205208
}

0 commit comments

Comments
 (0)