SlideShare una empresa de Scribd logo
1 de 9
An Approach to Design .net
core Translation Tables
資料庫多語系設計
About
這篇文在做什麼?
To solve i18n requirements of database.
解決資料庫表格若有多語系需求,應如何實作的問題?
reference:Separate translation table approach
Concept
概念
資料表以最小異動的幅度,以「擴充」的概念新增某功能的語系擴充表,讓原
本的功能擁有多語系的資料集。
Using the idea of “extent” the original table to minimize the mofification of
original data.
Final Result using API
指定適當語系,相對應的資源
(如API) 回傳對應語系的內容
By specifing language code to
retrieve the contents in correct
language.
Table design
.net core - 設定支援的語系及預設語系
Supported Language and Default Language
public Startup(IConfiguration configuration)
{
Configuration = configuration;
_defaultCulture = new RequestCulture("en", "en");
_supportedCultures = new List<CultureInfo>
{
new CultureInfo("en"),
new CultureInfo("zh-CN"),
new CultureInfo("zh-TW"),
new CultureInfo("vi")
};
}
● 若相關資源找無對應語系,將rollback 回預設語系
Setup dotnet core localization
public void ConfigureServices(IServiceCollection services)
{
#region Localization
// Add the localization services to the services container
services.AddLocalization();
services.Configure<RequestLocalizationOptions>(
opts =>
{
/* your configurations*/
opts.DefaultRequestCulture = _defaultCulture;
// Formatting numbers, dates, etc.
opts.SupportedCultures = _supportedCultures;
// UI strings that we have localized.
opts.SupportedUICultures = _supportedCultures;
// Add Route provider to enable language selection via URL
opts.RequestCultureProviders.Insert(0, new RouteCultureProvider(_defaultCulture));
});
#endregion
}
● RouteCultureProvider 讓localization 機制可在網址列直接指定語系,如 /zh-TW/api
後端程式設計 - 將語系作為查詢條件的一部分
Language Code as Part of the Searching Criteria
/// <summary>
/// 設定檔的查詢條件
/// </summary>
public class ConfigCriteria :SearchCriteria
{
/// <summary>
/// 主設定檔的ID;可用來識別如多語系設定檔會有多個設定時,其上層的主設定檔為何。
/// </summary>
public string ConfigId { get; set; }
/// <summary>
/// 語系代碼
/// </summary>
public string Language { get; set; }
}
後端程式設計 - repository 針對語系進行查詢
Implement Query Predications
/// <summary>
/// 搜尋設定檔
/// </summary>
/// <param name="criteria"></param>
/// <returns></returns>
public IQueryable<Config> Search(ConfigCriteria criteria)
{
if (criteria == null)
return null;
IQueryable<Config> entities = this.GetAll();
if (!string.IsNullOrWhiteSpace(criteria.ConfigId))
entities = entities.Where(o => o.Id == criteria.ConfigId);
if (!string.IsNullOrWhiteSpace(criteria.Language))
{
var translations = this._Context.ConfigTranslation.Where(o => o.Lang.Equals(criteria.Language,
StringComparison.CurrentCultureIgnoreCase));
entities = from config in entities
select new Config
{
Id = config.Id,
Key = config.Key,
Value = config.Value,
Translations = translations.Where(t => t.ConfigId == config.Id).ToList()
};
}

Más contenido relacionado

Similar a An Approach to Design .net core Translation Tables

resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016Jason Barr
 
Government Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxGovernment Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxShivamDenge
 
Building Applications using Apache Hadoop
Building Applications using Apache HadoopBuilding Applications using Apache Hadoop
Building Applications using Apache HadoopC4Media
 
Product Update: Customization with Rosette
Product Update: Customization with RosetteProduct Update: Customization with Rosette
Product Update: Customization with RosetteBasis Technology
 
Everything multilingual in Drupal 8 (2015 November)
Everything multilingual in Drupal 8 (2015 November)Everything multilingual in Drupal 8 (2015 November)
Everything multilingual in Drupal 8 (2015 November)Gábor Hojtsy
 
Hibernate(H8) In Action
Hibernate(H8) In ActionHibernate(H8) In Action
Hibernate(H8) In ActionPriyank
 
AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...
AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...
AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...Dr. Haxel Consult
 
Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8Acquia
 
Hadoop Frameworks Panel__HadoopSummit2010
Hadoop Frameworks Panel__HadoopSummit2010Hadoop Frameworks Panel__HadoopSummit2010
Hadoop Frameworks Panel__HadoopSummit2010Yahoo Developer Network
 
What's New With Azure AI
What's New With Azure AIWhat's New With Azure AI
What's New With Azure AIMarvin Heng
 
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdfconceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdfSahajShrimal1
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?mikaelbarbero
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 
Create a program using any of the following languages- Python- ASP-NET.pdf
Create a program using any of the following languages- Python- ASP-NET.pdfCreate a program using any of the following languages- Python- ASP-NET.pdf
Create a program using any of the following languages- Python- ASP-NET.pdfBlakegclKerrx
 
The OpenText Translator for Content Suite Platform by Cassia
The OpenText Translator for Content Suite Platform by CassiaThe OpenText Translator for Content Suite Platform by Cassia
The OpenText Translator for Content Suite Platform by CassiaSean MURPHY
 
Shiv shakti resume
Shiv shakti resumeShiv shakti resume
Shiv shakti resumeShiv Shakti
 

Similar a An Approach to Design .net core Translation Tables (20)

resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016resume-jbarr-linkedin-2016
resume-jbarr-linkedin-2016
 
Government Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptxGovernment Polytechnic Arvi-1.pptx
Government Polytechnic Arvi-1.pptx
 
Shivam PPT.pptx
Shivam PPT.pptxShivam PPT.pptx
Shivam PPT.pptx
 
MichaelDeMar-2015_a
MichaelDeMar-2015_aMichaelDeMar-2015_a
MichaelDeMar-2015_a
 
Building Applications using Apache Hadoop
Building Applications using Apache HadoopBuilding Applications using Apache Hadoop
Building Applications using Apache Hadoop
 
Product Update: Customization with Rosette
Product Update: Customization with RosetteProduct Update: Customization with Rosette
Product Update: Customization with Rosette
 
Everything multilingual in Drupal 8 (2015 November)
Everything multilingual in Drupal 8 (2015 November)Everything multilingual in Drupal 8 (2015 November)
Everything multilingual in Drupal 8 (2015 November)
 
hadoop_module
hadoop_modulehadoop_module
hadoop_module
 
Hibernate(H8) In Action
Hibernate(H8) In ActionHibernate(H8) In Action
Hibernate(H8) In Action
 
Product internationalization
Product internationalizationProduct internationalization
Product internationalization
 
AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...
AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...
AI-SDV 2021 - Holger Keibel; Daniele Puccinelli - Leveraging pre-trained lang...
 
Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8Multilingual Improvements for Drupal 8
Multilingual Improvements for Drupal 8
 
Hadoop Frameworks Panel__HadoopSummit2010
Hadoop Frameworks Panel__HadoopSummit2010Hadoop Frameworks Panel__HadoopSummit2010
Hadoop Frameworks Panel__HadoopSummit2010
 
What's New With Azure AI
What's New With Azure AIWhat's New With Azure AI
What's New With Azure AI
 
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdfconceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
 
Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?Language Server Protocol - Why the Hype?
Language Server Protocol - Why the Hype?
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Create a program using any of the following languages- Python- ASP-NET.pdf
Create a program using any of the following languages- Python- ASP-NET.pdfCreate a program using any of the following languages- Python- ASP-NET.pdf
Create a program using any of the following languages- Python- ASP-NET.pdf
 
The OpenText Translator for Content Suite Platform by Cassia
The OpenText Translator for Content Suite Platform by CassiaThe OpenText Translator for Content Suite Platform by Cassia
The OpenText Translator for Content Suite Platform by Cassia
 
Shiv shakti resume
Shiv shakti resumeShiv shakti resume
Shiv shakti resume
 

Último

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Último (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

An Approach to Design .net core Translation Tables

  • 1. An Approach to Design .net core Translation Tables 資料庫多語系設計
  • 2. About 這篇文在做什麼? To solve i18n requirements of database. 解決資料庫表格若有多語系需求,應如何實作的問題? reference:Separate translation table approach
  • 4. Final Result using API 指定適當語系,相對應的資源 (如API) 回傳對應語系的內容 By specifing language code to retrieve the contents in correct language.
  • 6. .net core - 設定支援的語系及預設語系 Supported Language and Default Language public Startup(IConfiguration configuration) { Configuration = configuration; _defaultCulture = new RequestCulture("en", "en"); _supportedCultures = new List<CultureInfo> { new CultureInfo("en"), new CultureInfo("zh-CN"), new CultureInfo("zh-TW"), new CultureInfo("vi") }; } ● 若相關資源找無對應語系,將rollback 回預設語系
  • 7. Setup dotnet core localization public void ConfigureServices(IServiceCollection services) { #region Localization // Add the localization services to the services container services.AddLocalization(); services.Configure<RequestLocalizationOptions>( opts => { /* your configurations*/ opts.DefaultRequestCulture = _defaultCulture; // Formatting numbers, dates, etc. opts.SupportedCultures = _supportedCultures; // UI strings that we have localized. opts.SupportedUICultures = _supportedCultures; // Add Route provider to enable language selection via URL opts.RequestCultureProviders.Insert(0, new RouteCultureProvider(_defaultCulture)); }); #endregion } ● RouteCultureProvider 讓localization 機制可在網址列直接指定語系,如 /zh-TW/api
  • 8. 後端程式設計 - 將語系作為查詢條件的一部分 Language Code as Part of the Searching Criteria /// <summary> /// 設定檔的查詢條件 /// </summary> public class ConfigCriteria :SearchCriteria { /// <summary> /// 主設定檔的ID;可用來識別如多語系設定檔會有多個設定時,其上層的主設定檔為何。 /// </summary> public string ConfigId { get; set; } /// <summary> /// 語系代碼 /// </summary> public string Language { get; set; } }
  • 9. 後端程式設計 - repository 針對語系進行查詢 Implement Query Predications /// <summary> /// 搜尋設定檔 /// </summary> /// <param name="criteria"></param> /// <returns></returns> public IQueryable<Config> Search(ConfigCriteria criteria) { if (criteria == null) return null; IQueryable<Config> entities = this.GetAll(); if (!string.IsNullOrWhiteSpace(criteria.ConfigId)) entities = entities.Where(o => o.Id == criteria.ConfigId); if (!string.IsNullOrWhiteSpace(criteria.Language)) { var translations = this._Context.ConfigTranslation.Where(o => o.Lang.Equals(criteria.Language, StringComparison.CurrentCultureIgnoreCase)); entities = from config in entities select new Config { Id = config.Id, Key = config.Key, Value = config.Value, Translations = translations.Where(t => t.ConfigId == config.Id).ToList() }; }