<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

global $swifty_build_use;

global $ssd_oLocale;
$ssd_oLocale = array();

//$testPreLocale = '';
//if( $swifty_build_use != 'build' ) {
//    $testPreLocale = ':';
//}

// Have WP load the applicable language files
if( $swifty_build_use != 'build' ) {
    load_theme_textdomain( 'swifty-site-designer', get_template_directory() . '/languages' );
    load_theme_textdomain( 'swifty-site-designer', get_template_directory() . '/ssd/lib/swifty_plugin/languages' );
} else {
    load_theme_textdomain( 'swifty-site-designer', get_template_directory() . '/languages' );
}

// Read and process lang_js.pot so we get a list of all strins used in javascipt and mustache

// outcommented because we only want js extracted translations and the syntax for long msgid's is different
// for swifty-nl_NL.po a better regex is needed for reading multi-line msgid's:
// msgid ""
// "Start typing here or add content<br> by using the + button at the bottom."
// is using 2 lines

//if( $swifty_build_use != 'build' ) {
    $poSrc = swifty_read_text( get_template_directory() . '/languages/lang_js.pot' );
//} else {
//    $poSrc = swifty_read_text( get_template_directory() . '/languages/swifty-nl_NL.po' );
//}

preg_match_all( '/msgid\s+\"([^\"]*)\"/', $poSrc, $matches );

foreach( $matches[1] as $msgid ) {
    $ssd_oLocale[ $msgid ] = swifty__( $msgid, 'swifty-site-designer' );
}

//// for internal use we want to be sure everything is translated, for this we prefix ':'
//if ( $testPreLocale != '' ) {
//    foreach( $ssd_oLocale as $key ) {
//        $ssd_oLocale[ $key ] = $testPreLocale . $key;
//    }
//}