translation - How to Translate a string of an array inside a class?

I want to translate my functions.php with custom code in it.There I have a Class "Glbl_Helper" with a public s

I want to translate my functions.php with custom code in it.

There I have a Class "Glbl_Helper" with a public static array that contains strings like "translate_me".

Now I want to translate the strings using WPML. But If I do it like in the Text-Snipped with "translate_me" and "translate_me_2" I get the error:

Fatal error: Constant expression contains invalid operations in /www/.../functions.php on line 502

Line 502 is in the functions.php in my code and the line 502 is: public static $step_questions = array(


if ( ! class_exists( 'Glbl_Helper' ) ) {

    class Glbl_Helper
    {       
        // Added keys for question array below

        const QUESTION_KEY = "question";
        const ANSWER_KEY = "answer";
        const INVALID_ANSWER_KEY = "invalid_answer";

        const ANSWER_FILTER_KEY = "answer-type-filter";
        const ANSWER_FILTER_FLAGS_KEY = "answer-type-filter-flags";


        // Added static array to define questions for each child step, where a question needs to be answered


        public static $step_questions = array(     //This is the code line 502 from the error

            self::STEP_BROKER_SIGN => array(
                self::QUESTION_KEY => __("translate me", "text_domain"),

                self::ANSWER_KEY => esc_html__("translate_me_2", "text_domain"),
                self::INVALID_ANSWER_KEY => "translate_me_3",
                self::ANSWER_FILTER_KEY => FILTER_SANITIZE_STRING, 
                self::ANSWER_FILTER_FLAGS_KEY => FILTER_REQUIRE_SCALAR
            ),

        );


...


    }

}

Can anyone tell me how I have to change my code so I can use WPML String translation to translate the Questions and Answers in the Array?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744934660a4601945.html

相关推荐

  • translation - How to Translate a string of an array inside a class?

    I want to translate my functions.php with custom code in it.There I have a Class "Glbl_Helper" with a public s

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信