duansha8764 2016-02-25 22:36
浏览 22

PHP翻译使用diversen / simple-php-translation

I'm trying to follow the README file of this translator package, but I'm not sure I'm following… Please be aware that I have VERY LITTLE knowledge of PHP.

I have a project set up something like this:

lang/
--en/language.php
--es/language.php

templates/
--blocks/
----header.php
----[…]
--sections/
----home.php
----[…]

boot.php
index.php // This is where I include my templates and boot.php

My boot.php goes something like this:

<?php
include_once(__DIR__ . '/vendor/autoload.php');
$lang = (!empty($_GET['lang'])) ? $_GET['lang'] : 'es';

use diversen\lang;
use diversen\translate\extractor;

$l = new lang();
$l->setDirsInsideDir(__DIR__ . '/lang/');
$l->setDirsInsideDir(__DIR__ . '/templates/');
$l->loadLanguage($lang);

$e = new extractor();
$e->defaultLanguage = $lang;
$e->updateLang();

// This is just a shortcut function
function __($str) {
    return lang::translate($str);
}

By including boot.php in my "main template", index.php, I'd like to add all non-translated strings to their corresponding translation file, but they remain unchanged (ie. nothing is being appended to the translation files)

In my template files I'm using the shortcut function __() like so:

<?= __('Some string to translate'); ?>

And I'm seeing them rendered as NT: Some string to translate. I assume NT stands for Not Translated or something along those lines.

My apache error logs are not showing anything…

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大