All Projects → kevinresol → turnwing

kevinresol / turnwing

Licence: other
Type safe & hackable localization library for Haxe

Programming Languages

haxe
709 projects
Fluent
28 projects

Projects that are alternatives of or similar to turnwing

I18N-Portable
Simple and cross platform internationalization/translations for Xamarin and .NET
Stars: ✭ 102 (+161.54%)
Mutual labels:  localization
iXn
Control your localization of apps
Stars: ✭ 20 (-48.72%)
Mutual labels:  localization
locale-switcher
Browser Extension to quickly change your browser locale.
Stars: ✭ 75 (+92.31%)
Mutual labels:  localization
csv-localizer
Command Line Interface that convert CSV file to iOS, Android or JSON localizable strings
Stars: ✭ 84 (+115.38%)
Mutual labels:  localization
learn flutter theme
Learn flutter theme in this project
Stars: ✭ 30 (-23.08%)
Mutual labels:  localization
update localization
A Python Script that helps dealing with localizations in Xcode. It keeps track of Items that are already translated and doesnt replace them like genstrings does but appends new items. Moreover it is possible to specify extensions of files that should be scanned and to specify ignore patterns for Files that should be ignored
Stars: ✭ 39 (+0%)
Mutual labels:  localization
simplelocalize-cli
Command-line tool for SimpleLocalize
Stars: ✭ 37 (-5.13%)
Mutual labels:  localization
NALib
General purpose C sourcecode collection
Stars: ✭ 16 (-58.97%)
Mutual labels:  localization
ngx-translate-module-loader
Highly configurable and flexible translations loader for @ngx-translate/core
Stars: ✭ 31 (-20.51%)
Mutual labels:  localization
MultiplatformPlayground
Kotlin Multiplatform project in Jetpack Compose & SwiftUI with shared ViewModel layer and File upload
Stars: ✭ 72 (+84.62%)
Mutual labels:  localization
textpacks
Textpattern CMS language files.
Stars: ✭ 25 (-35.9%)
Mutual labels:  localization
Temp-l10n
Frozen - checkout https://github.com/TartaricAcid/Minecraft-Mod-Language-Package for Minecraft 1.12+
Stars: ✭ 13 (-66.67%)
Mutual labels:  localization
JuliaAutonomy
Julia sample codes for Autonomy, Robotics and Self-Driving Algorithms.
Stars: ✭ 21 (-46.15%)
Mutual labels:  localization
learnrxjs
Русскоязычная документация RxJS
Stars: ✭ 20 (-48.72%)
Mutual labels:  localization
sketch-crowdin
Connect your Sketch and Crowdin projects together
Stars: ✭ 35 (-10.26%)
Mutual labels:  localization
go-l10n
Lightweight yet powerful continuous localization solution for Go, based on Serge and Plurr.
Stars: ✭ 32 (-17.95%)
Mutual labels:  localization
socitrack
A wearable platform for social interaction studies
Stars: ✭ 16 (-58.97%)
Mutual labels:  localization
docker-compose
Docker compose for Weblate
Stars: ✭ 62 (+58.97%)
Mutual labels:  localization
fuse-device
Use the basic Device functions such as UUID and current localization from Fuse
Stars: ✭ 13 (-66.67%)
Mutual labels:  localization
resource-translator
A GitHub Action that automatically creates machine-translated PRs of translation files. Supported file formats include, .ini, .po, .restext, .resx, .xliff .json.
Stars: ✭ 44 (+12.82%)
Mutual labels:  localization

turnwing

Hackable localization library for Haxe

What?

Type safety

Translations are done with interfaces. You will never mis-spell the translation key anymore.

In many existing localization libraries, the translation function looks like this:

loc.translate('hello', {name: 'World'});
loc.translate('orange', {number: 1});

There is one and only one translation function and its type is String->Dynamic->String. That means it takes a String key, a Dynamic parameter object and returns a substituted string. Several things can go wrong here: wrong translation key, wrong param name or wrong param data type.

With turnwing, we have typed translators. Each of them is a user-defined function and typed specifically.

loc.hello('World'); // String->String
loc.orange(1); // Int->String

Peace of mind

There is only one place where errors could happen, that is when the localization data is loaded.

This is because data are validated when they are loaded. The data provider does all the heavy lifting to make sure the loaded data includes all the needed translation keys and values. As a result, there is no chance for actual translation calls to fail.

Hackable

Users can plug in different implementations at various part of the library.

For example, JsonProvider uses JSON as the underlying localization format. One can easily write a XmlProvider (perhaps with tink_xml).

Also, an ErazorTemplate may replace the default HaxeTemplate implementation.

Usage

import turnwing.*;
import turnwing.provider.*;
import turnwing.template.*;

interface MyLocale {
	function hello(name:String):String;
	function orange(number:Int):String;
	var sub(get, never):SubLocale;
}

interface SubLocale {
	function yo():String;
}

class Main {
	static function main() {
		var source = new ResourceStringSource(lang -> '$lang.json');
		var template = new HaxeTemplate();
		var loc = new Manager<MyLocale>(new JsonProvider<MyLocale>(source, template));
		loc.get('en').handle(function(o) switch o {
			case Success(localizer):
				// data prepared, we can now translate something
				$type(localizer); // MyLocale
				trace(localizer.hello('World')); // "Hello, World!"
				trace(localizer.orange(4)); // "There are 4 orange(s)!"
			case Failure(e):
				// something went wrong when fetching the localization data
				trace(e);
		});
	}
}

// and your json data looks like this:
{
	"hello": "Hello, ::name::!",
	"orange": "There are ::number:: orange(s)!",
	"sub": {
		"yo": "Yo!"
	}
}

Providers

JsonProvider

JsonProvider is a provider for JSON sources. Its data validation is powered by tink_json, which generates the validation code with macro at compile time according to the type information of the user-defined locale interface.

Requires a templating engine to interpolate the parameters. The interface is defined in Template.hx. HaxeTemplate is an implementation based on haxe.Template from the Haxe standard library.

Usage:

var source = new ResourceStringSource(lang -> '$lang.json');
var template = new HaxeTemplate();
var provider = new JsonProvider<MyLocale>(source, template);

To use it, install tink_json and include it as dependency in your project

FluentProvider (JS Only)

FluentProvider is a provider for Fluent.

Messages in the FTL file should be named the same as the Locale interface functions. Nested interfaces should be delimited by a dash (-). Please refer to the files in the tests/data/ftl folder as an example.

At the moment, the validation logic is incomplete and only performs a very rough check. So, runtime error may occur in a locale function call. This will be improved in the future.

Usage:

var source = new ResourceStringSource(lang -> '$lang.ftl');
var provider = new FluentProvider<MyLocale>(source);

To use it, you have to install the npm package @fluent/bundle

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].