From 2d9b20157957a55bd83875775085ed31c9062577 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:58:52 -0300 Subject: Squashed 'mod/translation_editor/' content from commit 9d86955 git-subtree-dir: mod/translation_editor git-subtree-split: 9d86955e6d8b6807578f5a9da0346ac1a146881c --- actions/add_custom_key.php | 64 ++++++++++++++++++++++++++ actions/add_language.php | 19 ++++++++ actions/delete.php | 20 +++++++++ actions/delete_language.php | 26 +++++++++++ actions/disable_languages.php | 23 ++++++++++ actions/make_translation_editor.php | 23 ++++++++++ actions/merge.php | 29 ++++++++++++ actions/translate.php | 76 +++++++++++++++++++++++++++++++ actions/translate_search.php | 84 +++++++++++++++++++++++++++++++++++ actions/unmake_translation_editor.php | 20 +++++++++ 10 files changed, 384 insertions(+) create mode 100644 actions/add_custom_key.php create mode 100644 actions/add_language.php create mode 100644 actions/delete.php create mode 100644 actions/delete_language.php create mode 100644 actions/disable_languages.php create mode 100644 actions/make_translation_editor.php create mode 100644 actions/merge.php create mode 100644 actions/translate.php create mode 100644 actions/translate_search.php create mode 100644 actions/unmake_translation_editor.php (limited to 'actions') diff --git a/actions/add_custom_key.php b/actions/add_custom_key.php new file mode 100644 index 000000000..47269dfd2 --- /dev/null +++ b/actions/add_custom_key.php @@ -0,0 +1,64 @@ +translations["en"])){ + $exists = true; + } + + if(!$exists){ + // save + + $custom_translations = array(); + + if($custom_translations = translation_editor_get_plugin("en", "custom_keys")){ + $custom_translations = $custom_translations["en"]; + } + + $custom_translations[$key] = $translation; + + $base_dir = elgg_get_data_path() . "translation_editor" . DIRECTORY_SEPARATOR; + if(!file_exists($base_dir)){ + mkdir($base_dir); + } + + $location = $base_dir . "custom_keys" . DIRECTORY_SEPARATOR; + if(!file_exists($location)){ + mkdir($location); + } + + $file_contents = ""; + + if(file_put_contents($location . "en.php", $file_contents)){ + + system_message(elgg_echo("translation_editor:action:add_custom_key:success")); + } else { + register_error(elgg_echo("translation_editor:action:add_custom_key:file_error")); + } + } else { + register_error(elgg_echo("translation_editor:action:add_custom_key:exists")); + } + } else { + register_error(elgg_echo("translation_editor:action:add_custom_key:invalid_chars")); + } + } else { + register_error(elgg_echo("translation_editor:action:add_custom_key:key_numeric")); + } + } else { + register_error(elgg_echo("translation_editor:action:add_custom_key:missing_input")); + } + + forward(REFERER); \ No newline at end of file diff --git a/actions/add_language.php b/actions/add_language.php new file mode 100644 index 000000000..4b324bee6 --- /dev/null +++ b/actions/add_language.php @@ -0,0 +1,19 @@ +guid, $role, true, "integer", $user->guid, ACCESS_PUBLIC)){ + $result = true; + } + } + + if(!$result){ + register_error(elgg_echo("translation_editor:action:make_translation_editor:error")); + } else { + system_message(elgg_echo("translation_editor:action:make_translation_editor:success")); + } + + forward(REFERER); \ No newline at end of file diff --git a/actions/merge.php b/actions/merge.php new file mode 100644 index 000000000..db1e75276 --- /dev/null +++ b/actions/merge.php @@ -0,0 +1,29 @@ +allowedprotocols[] = "javascript"; + + // fix allowed tags + $CONFIG->allowedtags["a"]["onclick"] = array(); + $CONFIG->allowedtags["span"]["id"] = array(); + + // get inputs + $current_language = get_input("current_language"); + $translate_input = get_input("translation"); + $plugin = get_input("plugin"); + $jquery = get_input("jquery", false); + + // Preparing jQuery result + $json_result = array(); + $json_result["result"] = false; + + if(translation_editor_is_translation_editor()){ + if(!empty($current_language) && !empty($translate_input) && !empty($plugin)){ + $translated = translation_editor_compare_translations($current_language, $translate_input); + + if(!empty($translated)){ + if(translation_editor_write_translation($current_language, $plugin, $translated)){ + if(!$jquery){ + system_message(elgg_echo("translation_editor:action:translate:success")); + } else { + $json_result["result"] = true; + } + } else { + if(!$jquery){ + register_error(elgg_echo("translation_editor:action:translate:error:write")); + } + } + } else { + translation_editor_delete_translation($current_language, $plugin); + if(!$jquery){ + system_message(elgg_echo("translation_editor:action:translate:no_changed_values")); + } else { + $json_result["result"] = true; + } + } + + // merge translations + translation_editor_merge_translations($current_language, true); + } else { + if(!$jquery){ + register_error(elgg_echo("translation_editor:action:translate:error:input")); + } + } + } else { + if(!$jquery){ + register_error(elgg_echo("translation_editor:action:translate:error:not_authorized")); + } + } + + if(!$jquery){ + forward(REFERER); + } else { + // Send JSON data + $json_string = json_encode($json_result); + + header("Content-Type: application/json; charset=UTF-8"); + header("Content-Length: " . strlen($json_string)); + header("Cache-Control: no-cache"); + header("Pragma: no-cache"); + + echo $json_string; + exit(); + } diff --git a/actions/translate_search.php b/actions/translate_search.php new file mode 100644 index 000000000..623828b39 --- /dev/null +++ b/actions/translate_search.php @@ -0,0 +1,84 @@ +allowedprotocols[] = "javascript"; + + // fix allowed tags + $CONFIG->allowedtags["a"]["onclick"] = array(); + $CONFIG->allowedtags["span"]["id"] = array(); + + // get inputs + $current_language = get_input("current_language"); + $translation = get_input("translation"); + $jquery = get_input("jquery", false); + + // Preparing jQuery result + $json_result = array(); + $json_result["result"] = false; + + if(translation_editor_is_translation_editor()){ + $trans = get_installed_translations(); + + if(!empty($current_language) && !empty($translation) && array_key_exists($current_language, $trans)){ + foreach($translation as $plugin => $translate_input){ + // merge with existing custom translations + if($custom_translation = translation_editor_read_translation($current_language, $plugin)){ + $translate_input = array_merge($custom_translation, $translate_input); + } + + $translated = translation_editor_compare_translations($current_language, $translate_input); + + if(!empty($translated)){ + if(translation_editor_write_translation($current_language, $plugin, $translated)){ + if(!$jquery){ + system_message(elgg_echo("translation_editor:action:translate:success")); + } else { + $json_result["result"] = true; + } + } else { + if(!$jquery){ + register_error(elgg_echo("translation_editor:action:translate:error:write")); + } + } + } else { + translation_editor_delete_translation($current_language, $plugin); + if(!$jquery){ + system_message(elgg_echo("translation_editor:action:translate:no_changed_values")); + } else { + $json_result["result"] = true; + } + } + } + + // merge translations + translation_editor_merge_translations($current_language, true); + } else { + if(!$jquery){ + register_error(elgg_echo("translation_editor:action:translate:error:input")); + } + } + } else { + if(!$jquery){ + register_error(elgg_echo("translation_editor:action:translate:error:not_authorized")); + } + } + + if(!$jquery){ + forward(REFERER); + } else { + // Send JSON data + $json_string = json_encode($json_result); + + header("Content-Type: application/json; charset=UTF-8"); + header("Content-Length: " . strlen($json_string)); + header("Cache-Control: no-cache"); + header("Pragma: no-cache"); + + echo $json_string; + exit(); + } diff --git a/actions/unmake_translation_editor.php b/actions/unmake_translation_editor.php new file mode 100644 index 000000000..1872d7f6c --- /dev/null +++ b/actions/unmake_translation_editor.php @@ -0,0 +1,20 @@ +translation_editor); + $result = true; + } + + if(!$result){ + register_error(elgg_echo("translation_editor:action:unmake_translation_editor:error")); + } else { + system_message(elgg_echo("translation_editor:action:unmake_translation_editor:success")); + } + forward(REFERER); -- cgit v1.2.3