drago-ex/translator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

drago-ex/translator

最新稳定版本:v1.0.12

Composer 安装命令:

composer require drago-ex/translator

包简介

Drago Extension for Nette Framework providing localization support with a custom Translator service and DI integration.

README 文档

README

Simple and lightweight translator for Nette Framework, providing localization support using NEON translation files.

License: MIT PHP version Tests Coding Style CodeFactor Coverage Status

Requirements

  • PHP >= 8.3
  • Nette Framework
  • Composer

Installation

composer require drago-ex/translator 

Extension registration

Register the Drago\Localization\DI\TranslatorExtension in your Nette project by adding the following configuration to your neon file:

extensions: - Drago\Localization\DI\TranslatorExtension(translateDir: %appDir%/locale)

Use in the presenter

To use the translator in your presenter, add the TranslatorAdapter trait:

use Drago\Localization\TranslatorAdapter

Accessing the Current Language

You can access the currently set language using the following property:

$this->lang;

Get Translator Instance

To get the translator instance, use the getTranslator method:

$this->getTranslator();

Translation File Format

Translation files should be written in the NEON format. For example:

"Hello, world!": "Hello, world!"

Using Translations in Templates

You can translate strings directly in your Latte templates using the following syntax:

{_"Hello, world!"} {* Using a filter for translation *} {$var|translate}

Translating Forms

To use translations in forms, simply set the translator for the form:

$form->setTranslator($this->getTranslator());

Route Configuration for Language Switching

Set up your routes to support language prefixes. For example, you can define routes with language codes:

$router->addRoute('[<lang=en cs|en>/]<presenter>/<action>', 'Presenter:action');

Switching Languages in Templates

To switch between languages in your templates, you can use n:href to pass the selected language:

<a n:href="this, 'lang' => 'cs'">Czech</a> <a n:href="this, 'lang' => 'en'">English</a>

统计信息

  • 总下载量: 2.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固