Skip to content

Instantly share code, notes, and snippets.

View LazZiya's full-sized avatar
coding powerful nugets

Ziya Mollamahmut LazZiya

coding powerful nugets
View GitHub Profile
@LazZiya
LazZiya / xlocalizer-settings.json
Last active November 14, 2020 07:45
XLocalizer options in json settings file
{
"XLocalizerOptions": {
"ResourcesPath": "LocalizationResources",
"AutoAddKeys": true,
"AutoTranslate": true,
"UseExpressMemoryCache": true,
"TranslateFromCulture": "en",
"ValidationErrors": {
"CompareAttribute_MustMatch": "'{0}' and '{1}' do not match. They should not be different!",
"CreditCardAttribute_Invalid": "The {0} field is not a valid credit card number.",
@LazZiya
LazZiya / startup.cs
Created November 4, 2020 09:32
XLocalizer options to customize defatul error messages inline
services.AddRazorPages()
.AddXLocalizer<...>(ops =>
{
// ...
ops.ValidationErrors = new ValidationErrors
{
RequiredAttribute_ValidationError = "The {0} field is required.",
CompareAttribute_MustMatch = "'{0}' and '{1}' do not match.",
StringLengthAttribute_ValidationError = "The field {0} must be a string with a maximum length of {1}.",
// ...
@LazZiya
LazZiya / KebabConverter.cs
Last active October 20, 2020 11:25
Convert strings to kebab case https://dotnetfiddle.net/WSE6sy
public static class KebabConverter
{
public static string ToKebabCase(this string str)
{
// find and replace all parts that starts with one capital letter
var str1 = Regex.Replace(str, "[A-Z][a-z]+", m => $"-{m.ToString().ToLower()}");
// find and replace all parts that are all capital letters
var str2 = Regex.Replace(str1, "[A-Z]+", m => $"-{m.ToString().ToLower()}");
@LazZiya
LazZiya / startup.cs
Last active November 13, 2020 06:50
Asp.Net Core XLocalizer sample startup.cs file for Razor Pages localized with XML resource files and online translation.
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// ...
public void ConfigureServices(IServiceCollection services)
@LazZiya
LazZiya / Register.cshtml.cs
Last active November 4, 2020 09:25
Asp.Net Core XLocalizer sample localized input model of registration page
public class InputModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[StringLength(100, MinimumLength = 6)]
[DataType(DataType.Password)]
@LazZiya
LazZiya / Register.cshtml
Last active August 20, 2020 07:43
Asp.Net Core XLocalizer sample of registration form.
@page
@model RegisterModel
@{
ViewData["Title"] = "Register";
}
<h1 localize-content>@ViewData["Title"]</h1>
<div class="row">
<div class="col-md-4">