ABP實戰--修改語言配置XML至Json

從ABP官網下載的Zero的多語言配置默認是使用XML文件的,實際使用中XML是沒有Json簡潔明瞭的,因此咱們將其修改成Json格式。數據庫

  • 修改MyLocalizationConfigurer.cs文件

咱們在Core-Localization下找到LocalizationConfigurer.cs文件,將其替換爲:json

public static void Configure(ILocalizationConfiguration localizationConfiguration)
{
//得到dll的全路徑
var location = Assembly.GetEntryAssembly().Location;
var sourceDir = Directory.GetParent(location) + "/Localization/SourceFiles";

localizationConfiguration.Sources.Add(
new DictionaryBasedLocalizationSource(CeciConsts.LocalizationSourceName,
new JsonFileLocalizationDictionaryProvider(sourceDir)
)
);
}

注意,這裏得到咱們運行目錄下的/Localization/SourceFiles下的文件做爲資源文件。ide

  • 修改資源文件的拷貝

一樣的SourceFiles下,參照xml文件名添加對應的json文件,並F4設置其`複製到輸出目錄`爲`始終複製`。
添加的Json文件內容參照以下,`culture`標明具體的語言,詳細參照ABP文檔。ui

{
"culture": "en",
"texts": {
"HomePage": "Home page",
"About": "About",
"WellcomeMessage": "Welcome to Ceci!",
"FormIsNotValidMessage": "Form is not valid. Please check and fix errors.",
"TenantNameCanNotBeEmpty": "Tenant name can not be empty",
"InvalidUserNameOrPassword": "Invalid user name or password",
"ThereIsNoTenantDefinedWithName{0}": "There is no tenant defined with name {0}",
"TenantIsNotActive": "Tenant {0} is not active.",
"UserIsNotActiveAndCanNotLogin": "User {0} is not active and can not log in.",
"UserEmailIsNotConfirmedAndCanNotLogin": "Your email address is not confirmed. You can not login.",
"UserLockedOutMessage": "The user account has been locked out. Please try again later.",
"PleaseEnterLoginInformation": "Please enter login information",
"TenancyName": "Tenancy name",
"UserNameOrEmail": "User name or email",
"Password": "Password",
"RememberMe": "Remember me",
"LogIn": "Log in",
"LoginFailed": "Login failed!",
"NameSurname": "Name surname",
"UserName": "User name",
"Name": "Name",
"Surname": "Surname",
"EmailAddress": "Email address",
"Tenants": "Tenants",
"SavedSuccessfully": "Saved successfully",
"CreateNewTenant": "Create new tenant",
"AdminEmailAddress": "Admin email address",
"Save": "Save",
"Cancel": "Cancel",
"TenantName_Regex_Description": "Tenant name must be at least 2 chars, starts with a letter and continue with letter, number, dash or underscore.",
"DefaultPasswordIs": "Default password is {0}",
"CanBeEmptyToLoginAsHost": "Can be empty to login as host.",
"Register": "Register",
"OrLoginWith": "Or login with",
"WaitingForActivationMessage": "Your account is waiting to be activated by system admin.",
"TenantSelection": "Tenant Selection",
"TenantSelection_Detail": "Please select one of the following tenants.",
"Logout": "Logout",
"RegisterFormUserNameInvalidMessage": "Please don't enter an email address for username.",
"DatabaseConnectionString": "Database connection string",
"Users": "Users",
"IsActive": "Is active",
"FullName": "Full name",
"CreateNewUser": "Create new user",
"Yes": "Yes",
"No": "No",
"Optional": "Optional",
"LeaveEmptyToSwitchToHost": "Leave empty to switch to the host",
"CurrentTenant": "Current tenant",
"NotSelected": "Not selected",
"Change": "Change",
"ChangeTenant": "Change tenant",
"MultiLevelMenu": "Multi Level Menu",
"Back": "Back",
"SuccessfullyRegistered": "Successfully registered",
"WaitingForEmailActivation": "Your email address should be activated",
"Roles": "Roles",
"DisplayName": "Display Name",
"Edit": "Edit",
"Delete": "Delete",
"CreateNewRole": "Create new role",
"RoleName": "Role Name",
"Actions": "Actions",
"CouldNotCompleteLoginOperation": "Could not complete login operation. Please try again later.",
"CouldNotValidateExternalUser": "Could not validate external user",
"EditRole": "Edit role",
"EditTenant": "Edit tenant",
"EditUser": "Edit user",
"TenantIdIsNotActive{0}": "TenantId {0} is not active",
"UnknownTenantId{0}": "Unknown tenantId {0}",
"ThisFieldIsRequired": "This field is required",
"PleaseWait": "Please wait...",
"Administration": "Administration",
"ClearAll": "Clear all",
"ClearOthers": "Clear others",
"LabelOptions": "Label options",
"Permissions": "Permissions",
"RoleDescription": "Role description",
"Refresh": "Refresh",
"Create": "Create",
"UserDetails": "User details",
"UserRoles": "User roles",
"ConfirmPassword": "Confirm password",
"Version": "Version",
"On": "On",
"Off": "Off",
"AreYouSureWantToDelete": "Are you sure want to delete {0}?",
"StartTyping": "Start Typing",
"Skins": "Skins",
"Settings": "Settings"
}
}
  • 修改簡體中文

  ABP Zero中中文簡體的標識是zh-Hans,咱們須要修改掉,不然Jquery的多語言文件等是沒法匹配的。spa

  1. 修改Seed中的DefaultLanguagesCreator類中的標識,zh-Hans改成zh。
  2. 修改數據庫language表中的標識。
  3. 在Core的Localization/SourceFiles中新增Ceci-zh.json。並設置其始終複製。
  • 移除找不到Key時加的[]

  在Core中已經再也不建議使用Key的方式來使用默認語言,而是直接將需表達的默認語言表現爲Key,可是咱們移除掉默認語言的Json後,ABP會在顯示語言處加【】標識,咱們能夠移除這個標識:code

Configuration.Localization.WrapGivenTextIfNotFound = false;
相關文章
相關標籤/搜索