i18n

package module
v0.0.0-...-7faca0a Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: EUPL-1.2 Imports: 7 Imported by: 0

README

i18n

This repository is a template for developers to create custom HTML elements. It includes a Go backend, an Angular custom element, and a full release cycle configuration.

Getting Started

  1. Clone the repository:

    git clone https://github.com/snider/i18n.git
    
  2. Install the dependencies:

    cd i18n
    go mod tidy
    cd ui
    npm install
    
  3. Run the development server:

    go run ./cmd/i18n serve
    

    This will start the Go backend and serve the Angular custom element.

Usage

To see how to use the i18n library in your own Go program, check out the example in the examples/simple directory.

To run the example, use the following command:

go run ./examples/simple

Building the Custom Element

To build the Angular custom element, run the following command:

cd ui
npm run build

This will create a single JavaScript file in the dist directory that you can use in any HTML page.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the EUPL-1.2 License - see the LICENSE file for details.

Documentation

Overview

Package i18n provides internationalization and localization services.

It is designed to be a simple, straightforward i18n solution that should be well-suited to most applications.

Getting Started

To use the i18n service, you first need to create a new instance:

i18nService, err := i18n.New()
if err != nil {
	log.Fatal(err)
}

Once you have a service instance, you can set the language and translate messages.

Locales

The i18n service loads locales from the `locales` directory. Locales are JSON files with the language code as the filename (e.g., `en.json`, `es.json`). The service uses the `embed` package to bundle the locales into the binary, so you don't need to worry about distributing the locale files with your application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct{}

Options holds configuration for the i18n service. This is a placeholder for future configuration options.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides internationalization and localization. It is the primary entrypoint for the i18n package.

func New

func New() (*Service, error)

New creates a new i18n service. The service is initialized with the English language as the default.

func (*Service) AvailableLanguages

func (s *Service) AvailableLanguages() []string

AvailableLanguages returns a list of available language codes.

func (*Service) GetAllMessages

func (s *Service) GetAllMessages(lang string) (map[string]string, error)

GetAllMessages returns all translation messages for the specified language. The keys are message IDs and values are the translated strings. If lang is empty, it uses the current language.

func (*Service) SetBundle

func (s *Service) SetBundle(bundle *i18n.Bundle)

SetBundle is a test helper to inject a bundle.

func (*Service) SetLanguage

func (s *Service) SetLanguage(lang string) error

SetLanguage sets the language for the i18n service. The language tag should be a valid BCP 47 language tag (e.g., "en", "en-US"). If the language is not supported, an error is returned.

func (*Service) Translate

func (s *Service) Translate(messageID string, args ...interface{}) string

Translate translates a message by its ID. It accepts an optional template data argument to interpolate into the translation. If the message is not found, the message ID is returned.

Directories

Path Synopsis
cmd
i18n command

Jump to

Keyboard shortcuts

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