From bed5921bb6bd1c7370ce73f8a4de8807f738237c Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 2 Jun 2017 10:29:49 +0300 Subject: [PATCH] UIString static construction - issue #361 --- src/dlangui/core/i18n.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/dlangui/core/i18n.d b/src/dlangui/core/i18n.d index 3e5926da..2b25a7d6 100644 --- a/src/dlangui/core/i18n.d +++ b/src/dlangui/core/i18n.d @@ -26,6 +26,14 @@ from DLangUI framework with resources of application. Set interface language using Platform.instance.uiLanguage in UIAppMain during initialization of application settings: --- Platform.instance.uiLanguage = "en"; + +/// create by id - string STR_MENU_HELP="Help" must be added to translation resources +UIString help1 = UIString.fromId("STR_MENU_HELP"); +/// create by id and fallback string +UIString help2 = UIString.fromId("STR_MENU_HELP", "Help"d); +/// create from raw string +UIString help3 = UIString.fromRaw("Help"d); + --- @@ -132,6 +140,16 @@ struct UIString { return _value.length == 0 && _id.length == 0; } + /// create UIString from id - will be translated; fallback value can be provided for cases if translation is not found + static UIString fromId(string ID, dstring fallback = null) { + return UIString(ID, fallback); + } + + /// Create UIString from raw string value - will not be translated + static UIString fromRaw(dstring rawValue) { + return UIString(null, rawValue); + } + /** Default conversion to dstring */ alias value this; }