Support » Plugin: Theme and plugin translation for Polylang (TTfP) » Allow custom directory to scan theme

  •     /**
         * Find strings in themes.
         *
         * @return array
         */
        public function run_theme_scanner() {
            $data = [];
            $themes = wp_get_themes();
    
            $settings = Polylang_Theme_Translation_Settings::getInstance();
    
            foreach ($themes as $name => $theme) {
                if (in_array($name, $settings['themes'])) {
                    $data[$name] = $this->register_stings_from_dir($theme->theme_root . DIRECTORY_SEPARATOR . $name . '/templates', $name); // add filter here
                }
            }
    
            return $data;
        }
    
    

    All my views are in templates directory. If I scan theme I have a lot of differences string not from my domain.

    Or you can add input before settings to include or exclude director from root theme. Example (with common separations):

    Include: templates, src

    Thanks for develop your plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Marcin Kazmierski

    (@marcinkazmierski)

    hello @bartbury,

    curentlly function “get_files_from_dir($dir_name)” works recursively.

    So files from the src and template directories should also be included.

    If your theme has irregular domian, you can use filter: “ttfp_domains” to modify list of text domains and add your custom domian like:

    add_filter('ttfp_domains', 'custom_ttfp_domains', 10, 1);
    function custom_ttfp_domains(array $domains)
    {
    $domains[] = "my-custom-domain";
    return $domains;
    }

    List of text domains is displayed on “TTfP Settings” page to select them for translation by polylang engine.

    Thread Starter bartbury

    (@bartbury)

    The problem is not with domain but with recursively directories.

    For example I have this string to translate:

    File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.
    my_boo
    boo
    foo

    What is this 🙂 from vendor o node_modules.

    If I change this line work very nice.

    $data[$name] = $this->register_stings_from_dir($theme->theme_root . DIRECTORY_SEPARATOR . $name . '/templates', $name);
    // add teampltes
    Plugin Author Marcin Kazmierski

    (@marcinkazmierski)

    @bartbury I have checked it, I think everything works fine.

    Maybe you didn’t notice the changes because I added simple cache for 1 minute?

    $cacheKey = sprintf("ttfp_cache_strings_from:%s:%s", $name, md5($path));
    $cacheVal = get_transient($cacheKey);
    if (is_array($cacheVal)) {
    $strings = $cacheVal;
    }

    Do you have still the same problem after 60sec? Can you show more details or screenshots? 🙂

    Thread Starter bartbury

    (@bartbury)

    Plugin Author Marcin Kazmierski

    (@marcinkazmierski)

    @bartbury ok, now I understand you 🙂
    I will add a filter (apply_filters) to exclude specific folders from scanner.
    I’ll let you know when it’s ready.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Allow custom directory to scan theme’ is closed to new replies.