dasBlog là một blog engine khá phổ hiện nay, tuy nhiên ở Việt Nam còn thấy rất ít blog dùng dasBlog. Phiên bản dasBlog 1.9 đã tích hợp tiếng Việt, nhưng để dùng hoàn toàn tiếng Việt theo cách của người Việt thì chưa được. Nên sẽ gây khó khăn cho người dùng.
Vì sao lại như vậy ?
dasBlog sẽ tự động hiển thị theo ngôn ngữ phía client tức là phía người dùng. Có nghĩa là nếu trình duyệt chọn Language là Vietnamese thì blog sẽ hiển thị Tiếng Việt, nếu blog chọn Language là English thì blog sẽ hiển thị theo tiếng Anh.
Vấn đề là ở Việt Nam thì chẳng mấy ai chọn Language trong trình duyệt cả, vậy là tiếng Việt sẽ không hiển thị mặc dù blog đã hỗ trợ tiếng Việt. Cần giải quyết thế nào để cho tiếng Việt hiển thị không phụ thuộc trình duyệt ?
Không có cách nào khác là dịch lại mã nguồn. Bạn cần sửa những gì trước khi dịch lại ?
Đoạn code cần sửa lại :
Bạn mở project newtelligence.DasBlog.Web.Core và tìm file SharedBasePage.cs sau đó tìm đoạn :
if ( siteConfig.UseUserCulture && Request.UserLanguages != null && Request.UserLanguages.Length > 0) { try { // The Accept-Language header's elements are defined as // <language-code>[;q=<quality>]. We're not interested in the // quality part and go by order and hence we cut off the part // after and including the semicolon. userCulture = System.Globalization.CultureInfo.CreateSpecificCulture(Request.UserLanguages[0].Split(';')[0]); } catch { // if the culture isn't installed, we fall back to the invariant culture. userCulture = System.Globalization.CultureInfo.InvariantCulture; } } else { userCulture = System.Globalization.CultureInfo.InvariantCulture; } System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = userCulture;
Dòng :
userCulture = System.Globalization.CultureInfo.CreateSpecificCulture(Request.UserLanguages[0].Split(';')[0]);
là dòng lấy thông tin ngôn ngữ từ trình duyệt, bạn sửa lại như sau và dịch lại :
userCulture = System.Globalization.CultureInfo.CreateSpecificCulture("vi-VN");
Nếu không muốn fix cứng tham số vi-VN trong code thì bạn cần code thêm 1 đoạn như sau :
tìn lớp : siteConfig thêm tham số UserCulture và tạo method cho nó, sau đó vào file siteSecurity.config khai thêm dòng :
<UserCulture>vi-VN</UserCulture >
và dòng code trên thì sửa lại thành :
userCulture = System.Globalization.CultureInfo.CreateSpecificCulturesiteConfig.UserCulture );
Sau khi hoàn tất bạn sẽ có một blog như blog của tôi.
Chúc bạn có một blog đẹp !!!