218 lines
6.8 KiB
C#
218 lines
6.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using LingAdmin.API.Data;
|
|
using LingAdmin.API.Models;
|
|
using LingAdmin.API.DTOs;
|
|
using System.Text.Json;
|
|
|
|
namespace LingAdmin.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/i18n")]
|
|
public class I18nController : ControllerBase
|
|
{
|
|
private readonly AppDbContext _context;
|
|
private readonly ILogger<I18nController> _logger;
|
|
|
|
public I18nController(AppDbContext context, ILogger<I18nController> logger)
|
|
{
|
|
_context = context;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet("manifest")]
|
|
public async Task<ActionResult<ApiResponse<object>>> GetManifest()
|
|
{
|
|
try
|
|
{
|
|
var languages = await _context.Languages
|
|
.Select(l => new { code = l.Code, name = l.Name, version = l.Version })
|
|
.ToListAsync();
|
|
|
|
var manifest = new { languages };
|
|
return Ok(ApiResponse<object>.Success(manifest));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error retrieving i18n manifest");
|
|
return StatusCode(500, ApiResponse<object>.Error("Internal server error", 500));
|
|
}
|
|
}
|
|
|
|
[HttpGet("lang/{languageCode}")]
|
|
public async Task<ActionResult<ApiResponse<object>>> GetLanguage(string languageCode)
|
|
{
|
|
try
|
|
{
|
|
// For simplicity, returning static translations
|
|
// In production, you'd want to store these in the database
|
|
var translations = languageCode.ToLower() switch
|
|
{
|
|
"en-us" => GetEnglishTranslations(),
|
|
"zh-cn" => GetChineseTranslations(),
|
|
_ => null
|
|
};
|
|
|
|
if (translations == null)
|
|
{
|
|
return NotFound(ApiResponse<object>.Error("Language not found", 404));
|
|
}
|
|
|
|
return Ok(ApiResponse<object>.Success(translations));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error retrieving language {LanguageCode}", languageCode);
|
|
return StatusCode(500, ApiResponse<object>.Error("Internal server error", 500));
|
|
}
|
|
}
|
|
|
|
private object GetEnglishTranslations()
|
|
{
|
|
return new
|
|
{
|
|
common = new
|
|
{
|
|
login = "Sign in",
|
|
loginDesc = "Enter your email below to login to your account",
|
|
email = "Email",
|
|
password = "Password",
|
|
submitLogin = "Sign In",
|
|
loggingIn = "Signing in...",
|
|
loginFailed = "Login failed. Please check your credentials.",
|
|
logout = "Logout",
|
|
dashboard = "Dashboard",
|
|
users = "Users",
|
|
settings = "Settings",
|
|
requisitions = "Requisitions"
|
|
},
|
|
menu = new
|
|
{
|
|
dashboard = "Dashboard",
|
|
users = "Users",
|
|
settings = "Settings",
|
|
requisitions = "Requisitions"
|
|
},
|
|
dashboard = new
|
|
{
|
|
title = "Dashboard",
|
|
totalRevenue = "Total Revenue",
|
|
subscriptions = "Subscriptions",
|
|
sales = "Sales",
|
|
activeNow = "Active Now"
|
|
},
|
|
users = new
|
|
{
|
|
title = "Users",
|
|
refresh = "Refresh Data",
|
|
name = "Name",
|
|
status = "Status",
|
|
createdAt = "Created At"
|
|
},
|
|
settings = new
|
|
{
|
|
title = "Settings",
|
|
desc = "System settings will be here."
|
|
},
|
|
requisitions = new
|
|
{
|
|
title = "Purchase Requisitions",
|
|
listTitle = "Requisition List",
|
|
create = "Create Requisition",
|
|
edit = "Edit Requisition",
|
|
id = "ID",
|
|
reqNo = "Request No",
|
|
requester = "Requester",
|
|
department = "Department",
|
|
date = "Date",
|
|
status = "Status",
|
|
description = "Description",
|
|
items = "Items",
|
|
itemName = "Item Name",
|
|
quantity = "Quantity",
|
|
price = "Price",
|
|
total = "Total",
|
|
actions = "Actions",
|
|
addItem = "Add Item",
|
|
save = "Save",
|
|
cancel = "Cancel",
|
|
delete = "Delete"
|
|
}
|
|
};
|
|
}
|
|
|
|
private object GetChineseTranslations()
|
|
{
|
|
return new
|
|
{
|
|
common = new
|
|
{
|
|
login = "登录",
|
|
loginDesc = "请输入您的邮箱登录账户",
|
|
email = "邮箱",
|
|
password = "密码",
|
|
submitLogin = "登录",
|
|
loggingIn = "登录中...",
|
|
loginFailed = "登录失败,请检查您的凭据。",
|
|
logout = "退出登录",
|
|
dashboard = "仪表盘",
|
|
users = "用户管理",
|
|
settings = "系统设置",
|
|
requisitions = "请购单"
|
|
},
|
|
menu = new
|
|
{
|
|
dashboard = "仪表盘",
|
|
users = "用户管理",
|
|
settings = "系统设置",
|
|
requisitions = "请购单"
|
|
},
|
|
dashboard = new
|
|
{
|
|
title = "仪表盘",
|
|
totalRevenue = "总收入",
|
|
subscriptions = "订阅数",
|
|
sales = "销售额",
|
|
activeNow = "当前在线"
|
|
},
|
|
users = new
|
|
{
|
|
title = "用户管理",
|
|
refresh = "刷新数据",
|
|
name = "姓名",
|
|
status = "状态",
|
|
createdAt = "创建时间"
|
|
},
|
|
settings = new
|
|
{
|
|
title = "系统设置",
|
|
desc = "这里将显示系统设置内容。"
|
|
},
|
|
requisitions = new
|
|
{
|
|
title = "请购单",
|
|
listTitle = "请购单列表",
|
|
create = "新建请购单",
|
|
edit = "编辑请购单",
|
|
id = "ID",
|
|
reqNo = "单号",
|
|
requester = "申请人",
|
|
department = "部门",
|
|
date = "日期",
|
|
status = "状态",
|
|
description = "描述",
|
|
items = "明细项",
|
|
itemName = "物品名称",
|
|
quantity = "数量",
|
|
price = "单价",
|
|
total = "总价",
|
|
actions = "操作",
|
|
addItem = "添加明细",
|
|
save = "保存",
|
|
cancel = "取消",
|
|
delete = "删除"
|
|
}
|
|
};
|
|
}
|
|
}
|