xcstrings

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 4 Imported by: 0

README

XCStrings

A Go library for working with .xcstrings files used for localization in iOS/macOS applications. This library allows you to read, write, and manipulate .xcstrings files programmatically.

Installation

To install the library, use the following command:

go get github.com/Arrim/xcstrings

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteXCStrings

func WriteXCStrings(filePath string, xcstrings *XCStrings) error

WriteXCStrings writes changes to the .xcstrings file

Types

type DeviceType

type DeviceType string

DeviceType represents the device type for variations.

type ExtractionState

type ExtractionState string

ExtractionState represents the state of the string extraction.

type Language

type Language string

Language represents a language code.

type Localization

type Localization struct {
	StringUnit *StringUnit `json:"stringUnit,omitempty"`
	Variations *Variation  `json:"variations,omitempty"`
}

Localization represents the localization data.

func (*Localization) AddPlural

func (l *Localization) AddPlural(pluralType PluralType, loc Localization)

AddPlural adds or updates a plural variation for the specified PluralType.

func (*Localization) IsDevice

func (l *Localization) IsDevice() bool

IsDevice checks if the Localization is a device variation.

func (*Localization) IsPlural

func (l *Localization) IsPlural() bool

IsPlural checks if the Localization is a plural variation.

func (*Localization) MarshalJSON

func (l *Localization) MarshalJSON() ([]byte, error)

MarshalJSON for Localization serializes stringUnit and variations.

func (*Localization) UnmarshalJSON

func (l *Localization) UnmarshalJSON(data []byte) error

UnmarshalJSON for Localization handles stringUnit and variations.

type PluralType

type PluralType string

PluralType represents pluralization types.

type StringState

type StringState string

StringState represents the translation state of a string.

type StringUnit

type StringUnit struct {
	State StringState `json:"state"`
	Value string      `json:"value"`
}

StringUnit represents the state and value of a localized string.

type Variation

type Variation struct {
	Plural map[PluralType]Localization `json:"plural,omitempty"`
	Device map[DeviceType]Localization `json:"device,omitempty"`
}

Variation represents either plural or device-specific localizations.

func (*Variation) MarshalJSON

func (v *Variation) MarshalJSON() ([]byte, error)

MarshalJSON for Variation serializes plural and device-specific localizations.

func (*Variation) UnmarshalJSON

func (v *Variation) UnmarshalJSON(data []byte) error

UnmarshalJSON for Variation handles plural and device-specific localizations.

type VariationType

type VariationType string

VariationType represents the type of variation (plural or device).

type XCString

type XCString struct {
	Comment         *string                   `json:"comment,omitempty"`
	Key             *string                   `json:"key,omitempty"`
	Localizations   map[Language]Localization `json:"localizations"`
	ExtractionState ExtractionState           `json:"extractionState,omitempty"`
	ShouldTranslate bool                      `json:"shouldTranslate"`
}

XCString represents a single localization entry.

func NewXCString

func NewXCString(key string, comment *string, extractionState ExtractionState, shouldTranslate bool, localizations map[Language]Localization) *XCString

NewXCString creates a new XCString instance.

func (*XCString) GetComment

func (x *XCString) GetComment() string

GetComment retrieves the comment for the XCString. Returns the comment as a string. If no comment is set, returns an empty string.

func (*XCString) GetLocalization

func (x *XCString) GetLocalization(language Language) (*Localization, bool)

GetLocalization retrieves a Localization by language from the XCString structure. Returns the Localization and a boolean indicating if the language was found.

func (*XCString) MarshalJSON

func (x *XCString) MarshalJSON() ([]byte, error)

MarshalJSON for XCString converts the map of Language to localizations.

func (*XCString) UnmarshalJSON

func (x *XCString) UnmarshalJSON(data []byte) error

UnmarshalJSON for XCString converts localizations into the map of Language.

type XCStrings

type XCStrings struct {
	Version        string              `json:"version"`
	SourceLanguage Language            `json:"sourceLanguage"`
	Strings        map[string]XCString `json:"strings"`
}

XCStrings represents the main structure of the localization file.

func ReadXCStrings

func ReadXCStrings(filePath string) (*XCStrings, error)

ReadXCStrings reads the .xcstrings file

func (*XCStrings) GetXCString

func (x *XCStrings) GetXCString(key string) (*XCString, bool)

GetXCString retrieves an XCString by key from the XCStrings structure. Returns the XCString and a boolean indicating if the key was found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL