forked from Elara6331/itd
		
	Add init functions to transliterators
This commit is contained in:
		@@ -12,7 +12,7 @@
 | 
				
			|||||||
### Features
 | 
					### Features
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Notification relay
 | 
					- Notification relay
 | 
				
			||||||
- Notificstion transliteration
 | 
					- Notification transliteration
 | 
				
			||||||
- Music control
 | 
					- Music control
 | 
				
			||||||
- Get info from watch (HRM, Battery level, Firmware version)
 | 
					- Get info from watch (HRM, Battery level, Firmware version)
 | 
				
			||||||
- Set current time
 | 
					- Set current time
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -120,7 +120,7 @@ var armenianMap = []string{
 | 
				
			|||||||
	"ւ", "",
 | 
						"ւ", "",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func (at *ArmenianTranslit) Init() {
 | 
				
			||||||
	lower := armenianMap
 | 
						lower := armenianMap
 | 
				
			||||||
	for i, val := range lower {
 | 
						for i, val := range lower {
 | 
				
			||||||
		if i%2 == 1 {
 | 
							if i%2 == 1 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,8 @@ import (
 | 
				
			|||||||
// conversion library.
 | 
					// conversion library.
 | 
				
			||||||
type ChineseTranslit struct{}
 | 
					type ChineseTranslit struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ChineseTranslit) Init() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ct *ChineseTranslit) Transliterate(s string) string {
 | 
					func (ct *ChineseTranslit) Transliterate(s string) string {
 | 
				
			||||||
	// Create buffer for final output
 | 
						// Create buffer for final output
 | 
				
			||||||
	outBuf := &bytes.Buffer{}
 | 
						outBuf := &bytes.Buffer{}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,8 @@ var compatJamoBlock = &unicode.RangeTable{
 | 
				
			|||||||
// This was translated to Go from the code in https://codeberg.org/Freeyourgadget/Gadgetbridge
 | 
					// This was translated to Go from the code in https://codeberg.org/Freeyourgadget/Gadgetbridge
 | 
				
			||||||
type KoreanTranslit struct{}
 | 
					type KoreanTranslit struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (KoreanTranslit) Init() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// User input consisting of isolated jamo is usually mapped to the KS X 1001 compatibility
 | 
					// User input consisting of isolated jamo is usually mapped to the KS X 1001 compatibility
 | 
				
			||||||
// block, but jamo resulting from decomposed syllables are mapped to the modern one. This
 | 
					// block, but jamo resulting from decomposed syllables are mapped to the modern one. This
 | 
				
			||||||
// function maps compat jamo to modern ones where possible and returns all other characters
 | 
					// function maps compat jamo to modern ones where possible and returns all other characters
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,9 +9,9 @@ func Transliterate(s string, useMaps ...string) string {
 | 
				
			|||||||
	// Create variable to store modified string
 | 
						// Create variable to store modified string
 | 
				
			||||||
	out := s
 | 
						out := s
 | 
				
			||||||
	// If custom map exists
 | 
						// If custom map exists
 | 
				
			||||||
	if customMap, ok := Transliterators["custom"]; ok {
 | 
						if custom, ok := Transliterators["custom"]; ok {
 | 
				
			||||||
		// Perform transliteration with it
 | 
							// Perform transliteration with it
 | 
				
			||||||
		out = customMap.Transliterate(out)
 | 
							out = custom.Transliterate(out)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// For every map to use
 | 
						// For every map to use
 | 
				
			||||||
	for _, useMap := range useMaps {
 | 
						for _, useMap := range useMaps {
 | 
				
			||||||
@@ -20,12 +20,13 @@ func Transliterate(s string, useMaps ...string) string {
 | 
				
			|||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// Get requested map
 | 
							// Get requested map
 | 
				
			||||||
		translitMap, ok := Transliterators[useMap]
 | 
							transliterator, ok := Transliterators[useMap]
 | 
				
			||||||
		if !ok {
 | 
							if !ok {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							transliterator.Init()
 | 
				
			||||||
		// Perform transliteration
 | 
							// Perform transliteration
 | 
				
			||||||
		out = translitMap.Transliterate(out)
 | 
							out = transliterator.Transliterate(out)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Return result
 | 
						// Return result
 | 
				
			||||||
	return out
 | 
						return out
 | 
				
			||||||
@@ -36,6 +37,7 @@ func Transliterate(s string, useMaps ...string) string {
 | 
				
			|||||||
// and returns the resulting string.
 | 
					// and returns the resulting string.
 | 
				
			||||||
type Transliterator interface {
 | 
					type Transliterator interface {
 | 
				
			||||||
	Transliterate(string) string
 | 
						Transliterate(string) string
 | 
				
			||||||
 | 
						Init()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Map implements Transliterator using a slice where
 | 
					// Map implements Transliterator using a slice where
 | 
				
			||||||
@@ -47,6 +49,8 @@ func (mt Map) Transliterate(s string) string {
 | 
				
			|||||||
	return strings.NewReplacer(mt...).Replace(s)
 | 
						return strings.NewReplacer(mt...).Replace(s)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (Map) Init() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Transliterators stores transliterator implementations for each supported language.
 | 
					// Transliterators stores transliterator implementations for each supported language.
 | 
				
			||||||
// Some of these were sourced from https://codeberg.org/Freeyourgadget/Gadgetbridge
 | 
					// Some of these were sourced from https://codeberg.org/Freeyourgadget/Gadgetbridge
 | 
				
			||||||
var Transliterators = map[string]Transliterator{
 | 
					var Transliterators = map[string]Transliterator{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user