中文版本 | English Version
NamBlog supports bilingual Chinese and English interface, and allows bloggers to create custom language packs.
NamBlog's internationalization covers the following:
- ✅ Navigation bar, buttons, form labels
- ✅ Article list, category, tag pages
- ✅ Login interface and editor interface
- ✅ Notification messages, error messages
- ✅ Common operation text (save, cancel, delete, etc.)
- ✅ API error messages and status information
- ✅ Validation error messages
- ✅ Operation success/failure feedback
- ❌ User-created article content (managed by bloggers themselves)
- ❌ Development logs and debug information (kept in English)
- ❌ GraphQL Schema descriptions (developer tools)
- ❌ Prompts and MCP descriptions (used by AI)
No configuration needed, the system will automatically:
-
🌐 Auto-detect browser language
- Chinese browser detected → Display Chinese interface
- Other languages detected → Display English interface
-
💾 Remember user choice
- After user switches language, the choice is saved in browser localStorage
- Next visit automatically uses the last selected language
-
✅ No configuration file needed
- Works out of the box, suitable for most scenarios
- Configuration only needed when forcing a specific language
Default priority:
- Language preference in localStorage (if exists)
- Browser language auto-detection
- English (fallback)
zh-CN: Simplified Chineseen-US: English
Bloggers can create translation files for any language, for example:
ja-JP: Japanesefr-FR: Frenchde-DE: German- etc.
When config.js is configured, the system determines the language in the following priority:
- LANGUAGE in config.js - Force specific language (highest priority)
- CUSTOM_LOCALE_CODE in config.js - Custom language pack
- localStorage.getItem('locale') - User's last selected language
- Browser language detection -
navigator.language(auto-detect) - English - Default fallback
💡 Tip: If you don't configure
config.js, the system defaults to priority 3 → 4 → 5
Edit the configuration area at the top of NamBlog.Web/js/config.js:
// ==================== Configuration Area (Can be modified in production) ====================
/**
* Language settings
* - 'zh-CN': Chinese
* - 'en-US': English
* - null: Auto-detect browser language
*/
const LANGUAGE = 'en-US'; // Change to your desired language
/**
* Custom language pack URL (optional)
*/
const CUSTOM_LOCALE_URL = null;
const CUSTOM_LOCALE_CODE = null;
// ==================== Configuration Area End ====================-
Copy
config.jslocally:cp NamBlog.Web/js/config.js /path/to/my-config.js
-
Modify configuration:
const LANGUAGE = 'en-US'; // Your language
-
Use docker-compose.yml:
services: namblog: image: namblog volumes: - ./my-config.js:/app/wwwroot/js/config.js:ro
-
Copy an existing language file as template:
# Use English as template (recommended) cp NamBlog.Web/js/i18n/locales/en-US.js \ NamBlog.Web/js/i18n/locales/ja-JP.js # Or use Chinese as template cp NamBlog.Web/js/i18n/locales/zh-CN.js \ NamBlog.Web/js/i18n/locales/ja-JP.js
-
Translate all text (keep keys unchanged, only change values):
export default { nav: { home: 'ホーム', // Japanese: Home categories: 'カテゴリ', // Japanese: Categories // ... translate other keys }, // ... };
Edit config.js:
const LANGUAGE = null; // Leave empty, use custom language
const CUSTOM_LOCALE_URL = './js/i18n/locales/ja-JP.js';
const CUSTOM_LOCALE_CODE = 'ja-JP';Use docker-compose.yml:
services:
namblog:
image: namblog
volumes:
- ./my-config.js:/app/wwwroot/js/config.js:ro
- ./my-locales/ja-JP.js:/app/wwwroot/js/i18n/locales/ja-JP.js:ro// config.js
const LANGUAGE = 'zh-CN';
const CUSTOM_LOCALE_URL = null;
const CUSTOM_LOCALE_CODE = null;// config.js
const LANGUAGE = 'en-US';
const CUSTOM_LOCALE_URL = null;
const CUSTOM_LOCALE_CODE = null;// config.js
const LANGUAGE = null; // Leave empty, use custom language
const CUSTOM_LOCALE_URL = './js/i18n/locales/ja-JP.js';
const CUSTOM_LOCALE_CODE = 'ja-JP';// config.js
const LANGUAGE = null; // Leave empty
const CUSTOM_LOCALE_URL = null;
const CUSTOM_LOCALE_CODE = null;- Clear browser cache:
localStorage.clear() - Force refresh: Ctrl+F5 or Cmd+Shift+R
- Check config.js syntax
- View browser console errors
Check:
- File path is correct
- File format is ES6 module (export default)
- File encoding is UTF-8
- View console warning messages
# Check file in container
docker exec -it <container> cat /app/wwwroot/js/config.js
# Check language file
docker exec -it <container> cat /app/wwwroot/js/i18n/locales/ja-JP.js
# View container logs
docker logs <container>const LANGUAGE = null;
const CUSTOM_LOCALE_URL = null;
const CUSTOM_LOCALE_CODE = null;Current version only uses one language at a time. To support user language switching:
- Add language switcher button in navigation bar
- Call
setLocale('zh-CN')orsetLocale('en-US') - User choice is saved in localStorage
Custom language files must contain all the following nodes (refer to en-US.js or zh-CN.js):
export default {
nav: { ... }, // Navigation bar (15 keys)
common: { ... }, // Common text (14 keys)
auth: { ... }, // Authentication (13 keys)
article: { ... }, // Article related (~30 keys)
editor: { ... }, // Editor (~80 keys)
pagination: { ... }, // Pagination (6 keys)
search: { ... }, // Search (3 keys)
errors: { ... } // Error messages (5 keys)
};Important:
- ✅ Keep all key names unchanged, only translate values
- ✅ Keep placeholders like
{count},{page}as is - ✅ File must be valid JavaScript ES6 module
- ✅ Ensure file encoding is UTF-8