This commit is contained in:
zhongjin 2023-05-06 09:31:39 +08:00
parent b60089eeb1
commit 1913497473
2 changed files with 311 additions and 0 deletions

View File

@ -0,0 +1,151 @@
<?php
/**
* OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
* all the essential functionalities required for any enterprise.
* Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
*
* OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA
*/
namespace OrangeHRM\Installer\Migration\V5_1_0;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query\QueryBuilder;
use OrangeHRM\Installer\Util\V1\Dto\TransUnit;
use Symfony\Component\Yaml\Yaml;
class TranslationHelper
{
protected ?LangStringHelper $langStringHelper = null;
private Connection $connection;
/**
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
/**
* @return Connection
*/
protected function getConnection(): Connection
{
return $this->connection;
}
/**
* @param string $language
* @return void
*/
public function addTranslations(string $language): void
{
$filepath = __DIR__ . '/translation/' . $language . '.yaml';
$yml = Yaml::parseFile($filepath);
$translations = array_shift($yml);
foreach ($translations as $translation) {
$sourceObj = new TransUnit($translation['target'], $translation['unitId']);
$this->saveTranslationRecord($translation['group'], $sourceObj, $language);
}
}
/**
* @param string $groupName
* @param TransUnit $source
* @param string $language
* @return void
*/
private function saveTranslationRecord(string $groupName, TransUnit $source, string $language): void
{
$groupId = $this->getLangStringHelper()->getGroupId($groupName);
$langStringId = $this->getLangStringHelper()->getLangStringIdByUnitIdAndGroup($source->getUnitId(), $groupId);
if ($langStringId == null) {
throw new Exception(
'Cannot add a translation to a non existent lang string: ' . $source->getUnitId()
);
}
$langId = $this->getLanguageId($language);
$existTranslation = $this->getTranslationRecord($langStringId, $langId);
if ($existTranslation != null) {
// TODO hanldle customized translations
} else {
$insetQuery = $this->createQueryBuilder();
$insetQuery->insert('ohrm_i18n_translate')
->values(
[
'lang_string_id' => ':langStringId',
'language_id' => ':langId',
'value' => ':target',
]
)
->setParameter('langStringId', $langStringId)
->setParameter('langId', $langId)
->setParameter('target', $source->getTarget())
->executeQuery();
}
}
/**
* @return LangStringHelper
*/
private function getLangStringHelper(): LangStringHelper
{
if (is_null($this->langStringHelper)) {
$this->langStringHelper = new LangStringHelper($this->getConnection());
}
return $this->langStringHelper;
}
/**
* @param string $langCode
* @return int
* @throws Exception
*/
private function getLanguageId(string $langCode): int
{
$searchQuery = $this->createQueryBuilder();
$searchQuery->select('language.id')
->from('ohrm_i18n_language', 'language')
->where('language.code = :langCode')
->setParameter('langCode', $langCode);
return $searchQuery->executeQuery()->fetchOne();
}
/**
* @return QueryBuilder
*/
protected function createQueryBuilder(): QueryBuilder
{
return $this->getConnection()->createQueryBuilder();
}
/**
* @param array $langStringId
* @param int $langId
* @return string
* @throws Exception
*/
private function getTranslationRecord(int $langStringId, int $langId): string
{
$searchQuery = $this->createQueryBuilder();
$searchQuery->select('translate.id')
->from('ohrm_i18n_translate', 'translate')
->where('translate.language_id = :langCode')
->andWhere('translate.lang_string_id = :langStringId')
->setParameter('langCode', $langId)
->setParameter('langStringId', $langStringId);
return $searchQuery->executeQuery()->fetchOne();
}
}

View File

@ -0,0 +1,160 @@
translations:
- { target: 湖南新空间系统技术有限公司 经纬航通HR团队, unitId: getting_started_with_orangehrm_message_2, group: help }
- { target: 经纬航通HR平台, unitId: getting_started_with_orangehrm, group: help }
- { target: 最新动态, unitId: buzz_latest_posts, group: dashboard }
- { target: 暂无动态, unitId: no_posts_added, group: dashboard }
- { target: 按单位分布, unitId: employee_distribution_by_sub_unit, group: dashboard }
- { target: 按位置分布, unitId: employee_distribution_by_location, group: dashboard }
- { target: 未定义, unitId: unassigned, group: dashboard }
- { target: 今日休假, unitId: employees_on_leave_today, group: dashboard }
- { target: 今日无休假, unitId: no_employees_are_on_leave_today, group: dashboard }
- { target: 假期未定义, unitId: leave_period_not_defined, group: dashboard }
- { target: 时间线, unitId: time_at_work, group: dashboard }
- { target: 今日, unitId: today, group: dashboard }
- { target: 本周, unitId: this_week, group: dashboard }
- { target: "{lastState}: {date} at {time} (GMT {timezoneOffset})", unitId: state_date_at_time_timezone_offset, group: dashboard }
- { target: "{lastState}: Today at {time} (GMT {timezoneOffset})", unitId: state_today_at_time_timezone_offset, group: dashboard }
- { target: 快速启动, unitId: quick_launch, group: dashboard }
- { target: 我的操作, unitId: my_actions, group: dashboard }
- { target: "{pendingActionsCount,plural, =0{No Records Found} one{(1) Leave Request to Approve} other{ (#) Leave Requests to Approve}}", unitId: n_pending_leave_request, group: dashboard }
- { target: "{pendingActionsCount,plural, =0{No Records Found} one{(1) Timesheet to Approve} other{ (#) Timesheets to Approve}}", unitId: n_pending_time_sheet, group: dashboard }
- { target: "{pendingActionsCount,plural, =0{No Records Found} one{(1) Performance Review to Evaluate} other{ (#) Performance Reviews to Evaluate}}", unitId: n_pending_performance_evaluate, group: dashboard }
- { target: "{pendingActionsCount,plural, =0{No Records Found} one{(1) Candidate to Interview} other{ (#) Candidates to Interview}}", unitId: n_pending_candidate_interview, group: dashboard }
- { target: 没有待执行的操作, unitId: no_pending_actions, group: dashboard }
- { target: "{pendingActionsCount,plural, =0{No Records Found} one{(1) Pending Self Review} other{ (#) Pending Self Reviews}}", unitId: n_pending_self_review, group: dashboard }
- { target: 配置, unitId: configurations, group: dashboard }
- { target: 只为其他用户显示休假的可访问员工, unitId: only_show_accessible_employees_on_leave_for_other_users, group: dashboard }
- { target: 无法使用, unitId: not_available, group: dashboard }
- { target: 语言包, unitId: language_package, group: admin }
- { target: 源语言, unitId: source_language, group: admin }
- { target: 模块, unitId: module, group: admin }
- { target: 目标文本, unitId: translated_text, group: admin }
- { target: 源文本, unitId: source_text, group: admin }
- { target: 注释, unitId: source_note, group: admin }
- { target: 显示, unitId: show, group: admin }
- { target: 全部, unitId: all, group: admin }
- { target: 已翻译, unitId: translated, group: admin }
- { target: 未翻译, unitId: not_translated, group: admin }
- { target: 翻译语言包, unitId: translate_language_package, group: admin }
- { target: 目录模块, unitId: directory_module, group: admin }
- { target: 排序, unitId: order, group: admin }
- { target: 服务器设置, unitId: server_settings, group: admin }
- { target: 绑定设置, unitId: bind_settings, group: admin }
- { target: 用户查找设置, unitId: user_lookup_settings, group: admin }
- { target: 数据对应, unitId: data_mapping, group: admin }
- { target: 附加设置, unitId: additional_settings, group: admin }
- { target: 主机, unitId: host, group: admin }
- { target: LDAP 服务器IP或主机名称不需要 ldap:// 或 ldaps://, unitId: ldap_host_input_hint, group: admin }
- { target: 端口, unitId: port, group: admin }
- { target: 加密, unitId: encryption, group: admin }
- { target: 查找范围, unitId: search_scope, group: admin }
- { target: 向上, unitId: ascending, group: general }
- { target: 向下, unitId: descending, group: general }
- { target: LDAP配置, unitId: ldap_configuration, group: general }
- { target: 有效, unitId: enable, group: general }
- { target: 用户状态, unitId: user_status, group: general }
- { target: 动态消息, unitId: buzz_newsfeed, group: buzz }
- { target: 提交, unitId: post, group: buzz }
- { target: 即将到来的周年纪念日, unitId: upcoming_anniversaries, group: buzz }
- { target: 此刻的心情和想法..., unitId: post_placeholder, group: buzz }
- { target: 分享照片, unitId: share_photos, group: buzz }
- { target: 分享视频, unitId: share_video, group: buzz }
- { target: 年, unitId: years, group: buzz }
- { target: 你的评论..., unitId: write_your_comment, group: buzz }
- { target: 删除, unitId: delete_post, group: buzz }
- { target: 编辑, unitId: edit_post, group: buzz }
- { target: 最多回复, unitId: most_recent_posts, group: buzz }
- { target: 最多点赞, unitId: most_liked_posts, group: buzz }
- { target: 最多评论, unitId: most_commented_posts, group: buzz }
- { target: 分享, unitId: share, group: buzz }
- { target: 视频链接, unitId: video_url, group: buzz }
- { target: 粘贴视频链接地址, unitId: paste_video_url, group: buzz }
- { target: 添加照片, unitId: add_photos, group: buzz }
- { target: "支持'gif', 'png', 'jpg', 'jpeg'等照片格式" , unitId: file_type_validation_message, group: buzz }
- { target: 2M, unitId: file_size_validation_message, group: buzz }
- { target: 分享, unitId: share_post, group: buzz }
- { target: 更多信息..., unitId: read_more, group: buzz }
- { target: 点赞, unitId: like, group: buzz }
- { target: ESC键返回, unitId: press_esc_to, group: buzz }
- { target: 暂无, unitId: no_posts_available, group: buzz }
- { target: 接下来的 30 天没有工作纪念日, unitId: no_work_anniversaries_for_the_next_30_days, group: buzz }
- { target: 所选项目将被永久删除。 你确定你要继续吗?, unitId: post_delete_confirmation_message, group: buzz }
- { target: 修改, unitId: edit_post, group: buzz }
- { target: '{likesCount,plural, =0{0 点赞} one{1 点赞} other{# 点赞}}', unitId: n_like, group: buzz }
- { target: '{commentCount,plural, =0{0 评论} one{1 评论} other{# 评论}}', unitId: n_comment, group: buzz }
- { target: '{shareCount,plural, =0{0 分享} one{1 分享} other{# 分享}}', unitId: n_share, group: buzz }
- { target: 无效的凭据, unitId: invalid_credentials, group: auth }
- { target: 帐户已禁用, unitId: account_disabled, group: auth }
- { target: 人员已开除, unitId: employee_is_terminated, group: auth }
- { target: 没有指定人员, unitId: employee_is_assigned, group: auth }
- { target: 如果电子邮件未送达,请联系您的管理员。, unitId: email_not_receive_note, group: auth }
- { target: 您可以点击该链接并设置一个新密码, unitId: follow_link_to_select_password, group: auth }
- { target: 重置密码链接已通过电子邮件发送给您。, unitId: reset_password_link_via_email, group: auth }
- { target: 返回登陆, unitId: back_to_login, group: auth }
- { target: 系统未配置重置密码电子邮件通知。 请联系您的管理员重置密码, unitId: configured_receive_email_notification_note, group: auth }
- { target: 已成功发送重置密码链接, unitId: reset_password_link_sent_successfully, group: auth }
- { target: 请求新的密码重置令牌, unitId: request_new_password_token, group: auth }
- { target: 找不到用户帐户或重置密码令牌已过期, unitId: reset_password_token_expired_note, group: auth }
- { target: 需要凭据, unitId: credential_required, group: auth }
- { target: 您已请求访问一项关键管理员功能,并且需要在下方验证您的凭据, unitId: admin_access_note, group: auth }
- { target: 您的密码不应包含空格。, unitId: your_password_should_not_contain_spaces, group: auth }
- { target: 密码必须包含一个小写字母、一个大写字母、一个数字和一个特殊字符。 尝试不同的密码, unitId: must_contain_lower_case_upper_case_digit_character_message, group: auth }
- { target: 应该至少有 8 个字符, unitId: should_have_min_8_characters, group: auth }
- { target: 重设密码, unitId: reset_password, group: auth }
- { target: 请输入您的用户名以识别您的帐户以重置您的密码, unitId: username_identify_reset_note, group: auth }
- { target: 设置新密码, unitId: set_new_password, group: auth }
- { target: 外观, unitId: corporate_branding, group: general }
- { target: 请选择, unitId: select, group: general }
- { target: 更多信息, unitId: more, group: general }
- { target: 应该大于下限, unitId: should_be_greater_than_lower_bound, group: general }
- { target: 正在查找..., unitId: searching, group: general }
- { target: 语言包, unitId: language_packages, group: general }
- { target: 目录, unitId: directory, group: general }
- { target: 支持, unitId: support, group: general }
- { target: 维护, unitId: maintenance, group: general }
- { target: 保险, unitId: claim, group: claim }
- { target: 事由, unitId: events, group: claim }
- { target: 添加事由, unitId: add_event, group: claim }
- { target: 编辑事由, unitId: event_name, group: claim }
- { target: 费用类型, unitId: expense_types, group: claim }
- { target: 添加费用类型, unitId: add_expense_type, group: claim }
- { target: 编辑费用类型, unitId: edit_expense_type, group: claim }
- { target: 事由, unitId: event, group: claim }
- { target: 新建保险请求单, unitId: create_claim_request, group: claim }
- { target: 标注, unitId: remarks, group: claim }
- { target: 新建, unitId: create, group: claim }
- { target: 提交保险, unitId: submit_claim, group: claim }
- { target: 费用, unitId: expenses, group: claim }
- { target: 支付, unitId: pay, group: claim }
- { target: 数量, unitId: amount, group: claim }
- { target: 合计, unitId: expenses, group: claim }
- { target: "{count,plural, =0{没有数据} one{(1) 条记录} other{ (#) 条记录}}", unitId: n_records_found, group: general }
- { target: "{count,plural, =0{未选择数据} one{(1) 条数据} other{(#) 条数据}}", unitId: n_records_selected, group: general }
- { target: "在这里输入...", unitId: type_for_hints, group: general }
- { target: 未打卡, unitId: not_punched_in, group: attendance }
- { target: 打卡, unitId: punched_in, group: attendance }
- { target: 取消打卡, unitId: punched_out, group: attendance }
- { target: 输入关键词..., unitId: enter_comma_seperated_words, group: recruitment }
- { target: 人员查找, unitId: employee_reviews, group: performance }