SchoolPhysicalExamination/application/appbackups/controller/Language.php

211 lines
12 KiB
PHP
Raw Permalink Normal View History

2025-04-19 17:24:07 +08:00
<?php
namespace app\app\controller;
class Language extends Base
{
// 支持的语言列表
protected $supportedLanguages = [
'en' => 'English',
'zh' => 'Chinese',
'es' => 'Spanish',
'fr' => 'French',
'pt' => 'Portuguese',
'ar' => 'Arabic',
'ru' => 'Russian',
'de' => 'German'
];
// 语言映射表
protected $languageMap = [
'en' => [
'操作成功' => 'Success',
'体重' => 'Weight',
'身高' => 'Height',
'消瘦' => 'Slim',
'正常' => 'Normal',
'偏重' => 'Overweight',
'肥胖' => 'Obesity',
'反映和衡量一个人健康状况的重要标志之一' => "One of the important indicators reflecting and measuring a person's health status",
'人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大' => "The length of the longitudinal part of the human body is derived from its longitudinal growth and is greatly influenced by genetic factors",
'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' => "BMI is the body mass index, which is currently a commonly used international standard for measuring the degree of body fat, thinness, and health.",
'公斤' => "kg",
'CM' => "cm",
'年' => "-",
'月' => "-",
'日' => "",
'身体得分' => "Physical score",
'分' => "score",
'身体类型' => "body type",
'健美肌肉型' => "Bodybuilding muscle type",
'低' => "Low",
'偏低' => "Slightly low",
'标准' => "Standard",
'偏高' => "Slightly high",
'高' => "High",
'矮' => "Short",
'偏矮' => "Slightly short",
'脂肪率' => "Body Fat Percentage",
'体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。' => "Body fat percentage refers to the proportion of fat tissue in body composition. Measuring it provides a more accurate reflection of body fat levels (degree of obesity) than weight measurement alone.",
'脂肪量' => "Fat Mass",
'人体脂肪的重量' => "Body Fat Weight",
'肌肉率' => "Muscle Percentage",
'优' => "Excellent",
'根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。' => "Muscle percentage is a ratio derived from total muscle mass, body weight, height, etc. Its range determines a person's health status and strength level.",
'肌肉量' => "Muscle Mass",
'不足' => "Insufficient",
'肌肉量=实际体重*肌肉率' => "Muscle Mass = Actual Weight × Muscle Percentage",
'水分' => "Body Water",
'指人体内水分比例。' => "Refers to the proportion of water in the human body.",
'蛋白量' => "Protein Mass",
'蛋白量=实际体重*蛋白率' => "Protein Mass = Actual Weight × Protein Percentage",
'骨重' => "Bone Mass",
'单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。' => "Bone mass refers to the content of bone tissue, minerals (calcium, phosphorus, etc.), and bone matrix (collagen, proteins, inorganic salts, etc.) per unit volume, reflecting skeletal health.",
'蛋白率' => "Protein Percentage",
'人体内蛋白率含量。' => "The proportion of protein in the human body.",
'基础代谢' => "Basal Metabolic Rate (BMR)",
'指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率' => "The energy expenditure rate when the body is awake, completely at rest, and unaffected by muscle activity, ambient temperature, food intake, or mental stress.",
'内脏指数' => "Visceral Fat Index",
'警惕' => "Caution",
'危险' => "Danger",
'内脏脂肪指数' => "Visceral Fat Level",
'皮下脂肪' => "Subcutaneous Fat",
'皮下脂脂肪就是贮存于皮下的脂肪组织人体的脂肪大约有2/3贮存在皮下组织' => "Subcutaneous fat refers to adipose tissue stored under the skin. About two-thirds of body fat is stored subcutaneously.",
'肥胖等级' => "Obesity Level",
'体重不足' => "Underweight",
'肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' => "Obesity level indicates the disparity between actual and ideal weight, serving as a diagnostic criterion for obesity.",
'孩子可能存在营养不良对于处在生长发育期的孩子而言蛋白质、碳水化合物、维生素和矿物质这四类营养素非常重要。建议补充足够的蛋白质、锌、钙、铁、维生素D、赖氨酸等营养。建议补充含鸡内金山楂膏健脾开胃类药食同源食物。' => "The child may be malnourished: For growing children, protein, carbohydrates, vitamins, and minerals are critical. Ensure adequate intake of protein, zinc, calcium, iron, vitamin D, lysine, etc. Consider herbal foods like chicken gizzard-hawthorn paste to improve digestion and appetite.",
'孩子可能存在营养不良对于处在生长发育期的孩子而言最有利于长高的营养素是蛋白质、碳水化合物、维生素和矿物质四类。建议补充足够的蛋白质、锌、铁、钙、维生素D、赖氨酸等营养。' => "The child may be malnourished: For children in their growth and development stage, the most beneficial nutrients for height growth are proteins, carbohydrates, vitamins, and minerals. It is recommended to ensure adequate intake of nutrients such as protein, zinc, iron, calcium, vitamin D, and lysine.",
'坚持适当、科学的跳跃运动能够科学地增加学生体重,能够改善学 生体重过低的情况;同时运动会消耗能量并加速胃肠蠕动,这会使孩子的食欲大开,再配合均衡的营养有利于孩子增重。' => "Moderate, scientifically designed jumping exercises can help underweight students gain weight by boosting energy expenditure and gastrointestinal motility, thereby increasing appetite. Combined with balanced nutrition, this supports healthy weight gain.",
'3-7岁的孩子骑两轮车、拍踢球、打篮球、游泳、爬山每天高强度运动不超过30分钟。' => "Ages 37: Bicycling, ball games, basketball, swimming, hiking. Limit high-intensity exercise to 30 minutes daily.",
'该年龄段睡眠时间建议9-11小时' => "Recommended sleep duration for this age group: 911 hours.",
'孩子开始对于赞赏、鼓励、认同和肯定有需求,而且此阶段父亲在孩子的性格塑造、情绪控制以及责任感培养方面扮演着重要的角色,必须告诉孩子什么事应该做、什么事不应该做,并经常性地给孩子一些积极地暗示。例如,可以时常向孩子表达“我会一直在你身边,不要害怕””我对你的进步都看在眼里等类似的话语。' => "Children begin to crave praise, encouragement, and validation. Fathers play a key role in shaping character, emotional regulation, and responsibility during this phase. Clearly define boundaries while offering positive affirmations (e.g., 'Im always here for you,' 'I see your progress').",
'《中华人民共和国卫生行业标准WS 423-2013》' => "《Chinese Health Industry Standard WS 423-2013》",
'《中华人民共和国卫生行业标准WS/T 612-2018》' => "《Chinese Health Industry Standard WS/T 612-2018》",
'《中华人民共和国卫生行业标准WS/T1586-2018》' => "《Chinese Health Industry Standard WS/T 1586-2018》",
'《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (519 Years)》",
'头围' => "Head Circumference",
'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.",
],
// 可以添加更多语言映射
];
/**
* 处理多国语言翻译
*
* @param string $language 目标语言代码
* @param mixed $data 要翻译的数据(字符串或数组)
* @return mixed 翻译后的数据
*/
public function handling_languages_from_multiple_countries($language, $data)
{
// dump($data);
// 验证语言是否支持
if (!$this->isLanguageSupported($language)) {
return $this->msg($data['data']);
}
// 如果是数组,递归处理每个元素
if (is_array($data)) {
// dump(2);
$data = $this->translateArray($language, $data);
return $this->msg($data['data']);
}
// 如果是字符串,直接翻译
if (is_string($data)) {
// dump(3);
return $this->translateString($language, $data);
}
// dump($data);
// 其他类型直接返回
return $this->msg($data['data']);
}
/**
* 检查语言是否支持
*
* @param string $language 语言代码
* @return bool
*/
protected function isLanguageSupported($language)
{
return isset($this->supportedLanguages[$language]);
}
/**
* 翻译数组
*
* @param string $language 目标语言
* @param array $array 要翻译的数组
* @return array 翻译后的数组
*/
protected function translateArray($language, array $array)
{
$result = [];
foreach ($array as $key => $value) {
// 保持键不变,只翻译值
$result[$key] = is_array($value)
? $this->translateArray($language, $value)
: $this->translateString($language, $value);
}
return $result;
}
/**
* 翻译字符串
*
* @param string $language 目标语言
* @param string $string 要翻译的字符串
* @return string 翻译后的字符串
*/
protected function translateString($language, $string)
{
// dump($string);
// 检查是否有该语言的映射表
if (!isset($this->languageMap[$language])) {
return $string;
}
// 检查是否有对应的翻译
return $this->languageMap[$language][$string] ?? $string;
}
/**
* 获取支持的语言列表
*
* @return array
*/
public function getSupportedLanguages()
{
return $this->supportedLanguages;
}
/**
* 添加新的语言翻译
*
* @param string $language 语言代码
* @param array $translations 翻译映射数组
* @return bool
*/
public function addTranslations($language, array $translations)
{
if (!$this->isLanguageSupported($language)) {
return false;
}
if (!isset($this->languageMap[$language])) {
$this->languageMap[$language] = [];
}
$this->languageMap[$language] = array_merge(
$this->languageMap[$language],
$translations
);
return true;
}
}