• Resolved albedo0

    (@albedo0)


    Hi,

    I really need help with translating a plugin I’ve been developing for a few years. The translation works for some elements but not for others, which is driving me crazy. Initially, I thought the issue was with Gutenberg blocks, but I realized other elements aren’t being translated either.

    I’ve tried many solutions all the day… Finally integrated the translation into my main class, instantiated on the plugin’s main page.

    namespace myplugin;
    use Exception;
    
    new Core();
    
    class Core {
        [...]
        public function __construct(){
            // Translation
            add_action('init', array($this, 'localization'));
        }
    
        public function localization() {
            load_plugin_textdomain('myplugin', false, plugin_basename(self::getPath('languages')));
        }
    }

    The translation is loaded as the major part of the plugin is correctly translated.

    When I use standard ‘echo’ statements, it generally works fine:

    <p><?php echo __( "The integration of the icons is then done through a shortcode.", 'myplugin'); ?></p>

    But I have a class, for example, where the translation doesn’t works:

    namespace myplugin;
    
    class ZipPack {
        [...]
    
        static public function upload() {
            try {
                [...]
                // Check if a file was uploaded
                if (empty($_FILES['myplugin-zip']['name'])) {
                    throw new \Exception( __("Please select a .zip file!", "myplugin"));
                }
            }
        }
    }

    I can’t translate this Exception… I’ve even tried:

    // Check if a file was uploaded
    if (empty($_FILES['myplugin-zip']['name'])) {
        _e("Please select a .zip file!", "managerforicomoon");
        throw new \Exception( __("Please select a .zip file!", "myplugin"));
    }

    Thank you for your help.

    • This topic was modified 9 months, 1 week ago by albedo0.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter albedo0

    (@albedo0)

    i have edited my post to hide the plugin for search engine… but i forget one instance… Like a can’t edit twice, i write the correct code i tried :

    // Check if a file was uploaded
    if (empty($_FILES['myplugin-zip']['name'])) {
        _e("Please select a .zip file!", "myplugin");
        throw new \Exception( __("Please select a .zip file!", "myplugin"));
    }
    Thread Starter albedo0

    (@albedo0)

    I find the solution i have created a init function to delay every treatement after loading translation.

    public function __construct(){
        if (is_admin()) {
           add_action('plugins_loaded', array($this, 'localization'));
        }
        add_action('plugins_loaded', array($this, 'init'));
    }
    
    public function init(){
       [...]
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Internationalization’ is closed to new replies.