transliteration.module in Transliteration 6.2
Same filename and directory in other branches
Provides transliteration for UTF-8 text input and sanitzes file names.
Uses data from the Text::Unidecode Perl library.
File
transliteration.moduleView source
<?php
/**
* @file
* Provides transliteration for UTF-8 text input and sanitzes file names.
*
* Uses data from the Text::Unidecode Perl library.
* @see http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm
*/
/**
* Transliterate UTF-8 text to ASCII.
*
* Takes an input string in any language and character set, and tries to
* represent it in ASCII characters by conveying, in Roman letters, the
* pronunciation expressed by the text in some other writing system.
*
* @param $input
* UTF-8 text input.
* @param $unknown
* Replacement string for characters that do not have a suitable ASCII
* equivalent.
* @param $source_langcode
* Optional ISO 639 language code that denotes the language of the input.
* Used to apply language-specific variations and defaults to the current
* display language. If transliteration takes place during output (instead
* of creation) and the source language is not known at that time, it is
* recommended to set this argument to 'en' to produce consistent results
* for all enabled languages.
* @return
* Transliterated text.
*/
function transliteration_get($input, $unknown = '?', $source_langcode = NULL) {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
return transliteration_process($input, $unknown, $source_langcode);
}
/**
* Implementation of hook_init().
*
* Transliterate and clean the names of files currently being uploaded.
*/
function transliteration_init() {
if (!empty($_FILES['files'])) {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
// Figure out language, which is available for node form submits.
$langcode = NULL;
if (!empty($_POST['language'])) {
$languages = language_list();
$langcode = isset($languages[$_POST['language']]) ? $_POST['language'] : NULL;
}
foreach ($_FILES['files']['name'] as $field => $filename) {
// Keep a copy of the unaltered file name.
$_FILES['files']['orig_name'][$field] = $filename;
$_FILES['files']['name'][$field] = transliteration_clean_filename($filename, $langcode);
}
}
}
Functions
Name | Description |
---|---|
transliteration_get | Transliterate UTF-8 text to ASCII. |
transliteration_init | Implementation of hook_init(). |