Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DCCS.LocalizedString.NetStandard provide a multilanguage string implementation and multilangue exceptions.

License

NotificationsYou must be signed in to change notification settings

DCCS-IT-Business-Solutions/DCCS.LocalizedString.NetStandard

Repository files navigation

DCCS.LocalizedString.NetStandard provide a multilanguage string implementation and multilangue exceptions.

The accessor keys for the strings have to be defined as static objects which can be found by reflection.There exist furthermore a tools which can create resource files in C# projects for the required keys.

Note: Take a look atDCCS.AspNetCore.LocalizedString for usage of this library in an ASP.NET Core project

Installation

InstallDCCS.LocalizedString.NetStandard with NuGet:

Install-Package DCCS.LocalizedString.NetStandard

Or via the .NET Core command line interface:

dotnet add package DCCS.LocalizedString.NetStandard

Either commands, from Package Manager Console or .NET Core CLI, will download and install DCCS.LocalizedString.NetStandard and all required dependencies.

Resource Creator Tool

This tools create resource file by using reflection out of your compiled .NET assembly

Install the tool in the package managment console, command prompt or powershell

dotnet tool install --global DCCS.LocalizedString.ProjectResourceCreator

To run the tool go to your project or solution folder and start

createprojectresource

This will create resource files for invariant and current user interface culture. If you want other resources run the tool with the cultures option (e.g. for es and fr):

createprojectresource --cultures es,fr

Important: For classic .net framework project ensure that you have build your projects first!

Note: Resource entries which values starts with '!' are ignored

Uninstall the tool in the package managment console, command prompt or powershell

dotnet tool uninstall --global DCCS.LocalizedString.ProjectResourceCreator

Do upgrade the tool to the lasted version, deinstall the previous and install the new

dotnet tool uninstall --global DCCS.LocalizedString.ProjectResourceCreatordotnet tool install --global DCCS.LocalizedString.ProjectResourceCreator

Examples

Simple console application sample:

usingSystem;usingSystem.Diagnostics;usingSystem.Globalization;usingDCCS.LocalizedString.NetStandard;classMyClass{// Declaration of the key - Must be static in none generic classesstaticreadonlyLocalizedStringKeyThisIsASample=newLocalizedStringKey("This is a sample application");// If you want use runtime parameters, use the LocalizedFormatKey and specifiy the name of the provided parametersstaticreadonlyLocalizedFormatKeyThisIsASampleError=newLocalizedFormatKey("This is a sample error thrown at {0}","Time Stamp");voidMain(){ITranslationServicetranslationService=newTranslationService(newITranslationProviderService[]{newResourceTranslationProvider()});ILocalizedStringlocalizedString=translationService.Create(ThisIsASample);// Write out the message in the current UI culture:Console.WriteLine(localizedString.GetText(CultureInfo.CurrentUICulture));// Write out the message in the current UI culture:Console.WriteLine(localizedString.GetText(CultureInfo.CurrentUICulture));// Write out the message in englishTrace.WriteLine(localizedString.GetText(CultureInfo.InvariantCulture));try{// To use runtimeparameters, specify a LocalizedFormatKey and a matching number of runtime parametersILocalizedStringlocalizedStringWithRuntimeParamters=translationService.Create(ThisIsASampleError,DateTime.Now);thrownewLocalizedException(localizedStringWithRuntimeParamters);}catch(Exceptione){ILocalizedStringlocalizedErrorMessage=LocalizedException.FindLocalizedMessage(e);if(localizedErrorMessage!=null)Console.WriteLine(localizedErrorMessage.GetText(CultureInfo.CurrentUICulture));elseConsole.WriteLine($"Internal error{e.Message}");ILocalizedStringcreatesAlwaysAUserFriendlyMessage=LocalizedException.CreateLocalizedMessage(translationService,e);// Will write out "Internal Error" if no LocalizedException was found in the exception hirachyConsole.WriteLine(createsAlwaysAUserFriendlyMessage.GetText(CultureInfo.CurrentUICulture));}// Create a localized string out of an enum - Note: the enum must be marked with an [Translated] attributeILocalizedStringlocalizedEnumValue=translationService.Create(Colors.Red);Console.WriteLine(localizedEnumValue.GetText(CultureInfo.CurrentUICulture));}[Translated]enumColors{Red,Blue,Green,[Translated("Dark Green")]// Provide default text, if the text of the enum value is not suitableGreenDark,}}

Contributing

All contributors are welcome to improve this project. The best way would be to start a bug or feature request and discuss the way you want find a solution with us.After this process, please create a fork of the repository and open a pull request with your changes. Of course, if your changes are small, feel free to immediately start your pull request without previous discussion.

License

This library isMIT licensed

About

DCCS.LocalizedString.NetStandard provide a multilanguage string implementation and multilangue exceptions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp