Skip to content
wiki.fftac.org

Dictionaryrepository - Source Excerpt 02

Back to Dictionaryrepository

Summary

This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/uaix-locale-router/src/DictionaryRepository.php so readers can inspect the evidence without opening the full source file.

**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/DictionaryRepository.php

/**
	 * Resolve a normalized path to a dictionary key.
	 *
	 * @param string $path Normalized path.
	 * @return string
	 */
	private static function navigation_dictionary_key_for_path( $path ) {
		$path = trim( (string) $path, '/' );
		$map  = array(
			''                                      => 'acn.nav.home',
			'archive'                              => 'acn.nav.archive',
			'research-agenda'                      => 'acn.nav.research_agenda',
			'research-library'                     => 'acn.nav.library',
			'timeline'                             => 'acn.nav.timeline',
			'symbols'                              => 'acn.nav.symbols',
			'apocalyptic-ai'                       => 'acn.nav.ai',
			'state-and-religion'                   => 'acn.nav.state_religion',
			'surveillance'                         => 'acn.nav.surveillance',
			'community-baseline'                   => 'acn.nav.community_baseline',
			'about'                                => 'acn.nav.about',
			'message-board'                        => 'acn.nav.board',
			'members'                              => 'acn.nav.members',
			'start-here'                           => 'acn.nav.start',
			'topics'                               => 'acn.nav.topics',
			'pre-christian-antichrist-history'     => 'acn.nav.pre_christian_antichrist_history',
			'antichrist-like-figures-eastern-philosophy' => 'acn.nav.eastern_antichrist_figures',
			'antichrist-as-redeemer-of-mankind'    => 'acn.nav.redeemer_mankind',
		);

		return isset( $map[ $path ] ) ? $map[ $path ] : '';
	}

	/**
	 * Resolve an English saved title to a dictionary key.
	 *
	 * @param string $title Menu title.
	 * @return string
	 */
	private static function navigation_dictionary_key_for_title( $title ) {
		$normalized = strtolower( trim( (string) $title ) );
		$normalized = function_exists( 'remove_accents' ) ? remove_accents( $normalized ) : $normalized;
		$normalized = (string) preg_replace( '/[^a-z0-9]+/', ' ', $normalized );
		$normalized = trim( $normalized );
		$map        = array(
			'home'               => 'acn.nav.home',
			'archive'            => 'acn.nav.archive',
			'research agenda'    => 'acn.nav.research_agenda',
			'research library'   => 'acn.nav.research_library',
			'library'            => 'acn.nav.library',
			'timeline'           => 'acn.nav.timeline',
			'symbols'            => 'acn.nav.symbols',
			'apocalyptic ai'     => 'acn.nav.ai',
			'state religion'     => 'acn.nav.state_religion',
			'state and religion' => 'acn.nav.state_religion',
			'surveillance'       => 'acn.nav.surveillance',
			'community baseline' => 'acn.nav.community_baseline',
			'about'              => 'acn.nav.about',
			'board'              => 'acn.nav.board',
			'message board'      => 'acn.nav.message_board',
			'members'            => 'acn.nav.members',
			'start here'         => 'acn.nav.start',
		);

		return isset( $map[ $normalized ] ) ? $map[ $normalized ] : '';
	}

	/**
	 * Return the dictionary manifest.
	 *
	 * @return array
	 */
	public static function dictionary_manifest() {
		$manifest = get_option( 'uaixlr_dictionary_manifest', array() );

		return is_array( $manifest ) ? $manifest : array();
	}

	/**
	 * Persist dictionary manifest data.
	 *
	 * @param array $manifest Manifest payload.
	 * @return void
	 */
	public static function save_dictionary_manifest( array $manifest ) {
		update_option( 'uaixlr_dictionary_manifest', $manifest );
	}

	/**
	 * Return a dictionary file path.
	 *
	 * @param string $locale_tag Locale tag.
	 * @return string
	 */
	public static function dictionary_path( $locale_tag ) {
		return trailingslashit( Plugin::dictionaries_dir() ) . LocaleValidator::canonicalize_tag( $locale_tag ) . '.json';
	}

	/**
	 * Return an empty runtime dictionary.
	 *
	 * @param string $locale_tag Locale tag.
	 * @return array
	 */
	private static function empty_dictionary( $locale_tag ) {
		return array(
			'meta'    => array(
				'locale'  => LocaleValidator::canonicalize_tag( $locale_tag ),
				'version' => 1,
			),
			'strings' => array(),
		);
	}

	/**
	 * Return dictionary paths in merge order.
	 *
	 * Bundled dictionaries provide deploy-time defaults. Uploaded dictionaries
	 * are applied last so reviewed production edits can still override them.
	 *
	 * @param string $locale_tag Locale tag.
	 * @return array
	 */
	private static function dictionary_candidate_paths( $locale_tag ) {
		$locale_tag   = LocaleValidator::canonicalize_tag( $locale_tag );
		$bundled_path = Plugin::data_path( 'dictionaries/' . $locale_tag . '.json' );
		$stored_path  = self::dictionary_path( $locale_tag );

		return array( $bundled_path, $stored_path );
	}

	/**
	 * Read and normalize a dictionary file.
	 *
	 * @param string $file_path Dictionary file path.
	 * @param string $locale_tag Locale tag.
	 * @return array
	 */
	private static function read_runtime_dictionary( $file_path, $locale_tag ) {
		if ( ! is_string( $file_path ) || '' === $file_path || ! file_exists( $file_path ) ) {
			return self::empty_dictionary( $locale_tag );
		}

		$dictionary = Json::decode_file( $file_path, array() );

		if ( ! is_array( $dictionary ) || ! isset( $dictionary['strings'] ) || ! is_array( $dictionary['strings'] ) ) {
			return self::empty_dictionary( $locale_tag );
		}

		$normalized = TranslationCatalog::normalize_dictionary_payload( $dictionary );

		return isset( $normalized['runtimeDictionary'] ) && is_array( $normalized['runtimeDictionary'] ) ? $normalized['runtimeDictionary'] : $dictionary;
	}

	/**
	 * Merge runtime dictionaries, letting later files override earlier values.
	 *
	 * @param array $base Base dictionary.
	 * @param array $overlay Overlay dictionary.
	 * @return array
	 */
	private static function merge_runtime_dictionaries( array $base, array $overlay ) {
		$base_meta     = isset( $base['meta'] ) && is_array( $base['meta'] ) ? $base['meta'] : array();
		$overlay_meta  = isset( $overlay['meta'] ) && is_array( $overlay['meta'] ) ? $overlay['meta'] : array();
		$base_strings  = isset( $base['strings'] ) && is_array( $base['strings'] ) ? $base['strings'] : array();
		$overlay_strings = isset( $overlay['strings'] ) && is_array( $overlay['strings'] ) ? $overlay['strings'] : array();

		return array(
			'meta'    => array_merge( $base_meta, $overlay_meta ),
			'strings' => array_merge( $base_strings, $overlay_strings ),
		);
	}

	/**
	 * Resolve the dictionary path, preferring uploads over bundled plugin data.
	 *
	 * @param string $locale_tag Locale tag.
	 * @return string
	 */
	private static function resolve_dictionary_path( $locale_tag ) {
		$locale_tag   = LocaleValidator::canonicalize_tag( $locale_tag );
		$stored_path  = self::dictionary_path( $locale_tag );
		$bundled_path = Plugin::data_path( 'dictionaries/' . $locale_tag . '.json' );

		if ( file_exists( $stored_path ) ) {
			return $stored_path;
		}

		if ( file_exists( $bundled_path ) ) {
			return $bundled_path;
		}

		return $stored_path;
	}

	/**
	 * Build a cache hash covering bundled and uploaded dictionary candidates.
	 *
	 * @param array  $file_paths Candidate paths.
	 * @param string $stored_default Stored-file fallback hash.
	 * @return string
	 */
	private static function dictionary_cache_hash( array $file_paths, $stored_default = 'missing' ) {
		$hashes = array();

		foreach ( $file_paths as $index => $file_path ) {
			$default  = 0 === (int) $index ? 'missing' : $stored_default;
			$hashes[] = self::dictionary_file_hash( $file_path, $default );
		}