Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Islandora 2395: Hook for Overwriting Human Readable Language Names #98

Open
wants to merge 5 commits into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions includes/utilities.inc
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,21 @@ function islandora_ocr_get_tesseract_installed_languages($tesseract = NULL) {
* otherwise the abbreviation is returned unaltered.
*/
function islandora_ocr_tesseract_language_name($language) {
$language_names = array(
'eng' => t('English'),
'fra' => t('French'),
'deu-frak' => t('German'),
'por' => t('Portugese'),
'spa' => t('Spanish'),
'hin' => t('Hindi'),
'jpn' => t('Japanese'),
'ita' => t('Italian'),
);
$language_names = module_invoke_all('get_ocr_tesseract_languages');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the comment I left in the api.php document, you'll also need to change the name of the hook here.

if (is_null($language_names)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module_invoke_all is going to return an array and in the default case an empty one. So you should probably do something like

if (count($language_names) == 0) {

$language_names = array(
'eng' => t('English'),
'fra' => t('French'),
'deu-frak' => t('German - Fraktur'),
'por' => t('Portuguese'),
'spa' => t('Spanish'),
'hin' => t('Hindi'),
'jpn' => t('Japanese'),
'ita' => t('Italian'),
'lat' => t('Latin'),
'deu' => t('German')
);
}
return isset($language_names[$language]) ? $language_names[$language] : $language;
}

Expand Down
36 changes: 36 additions & 0 deletions islandora_ocr.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @file
* Hooks for islandora_ocr module
*/


/**
*
* This hooks allows modules to define their own list of human readable names for the given tesseract abbreviation
*
*/
function hook_get_ocr_tesseract_languages() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook name should have the module name in it, so I would change this to hook_islandora_ocr_get_ocr_tesseract_languages(). It is a mouthful, but I think it is required.


// https://github.com/tesseract-ocr/tesseract/wiki/Data-Files
return array(
'swa' => t('Swahili'),
'swe' => t('Swedish'),
'syr' => t('Syriac'),
'tam' => t('Tamil'),
'tel' => t('Telugu'),
'tgk' => t('Tajik'),
'tgl' => t('Tagalog'),
'tha' => t('Thai'),
'tir' => t('Tigrinya'),
'tur' => t('Turkish'),
'uig' => t('Uighur; Uyghur'),
'ukr' => t('Ukrainian'),
'urd' => t('Urdu'),
'uzb' => t('Uzbek'),
'uzb_cyrl' => t('Uzbek - Cyrillic'),
'vie' => t('Vietnamese'),
'yid' => t('Yiddish'),
);
}