dglee87 / get-simple-cms

Automatically exported from code.google.com/p/get-simple-cms
GNU General Public License v3.0
0 stars 0 forks source link

Transliteration #195

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://get-simple.info/forum/topic/1671/include-the-slug-transliteration-plugin-
into-the-core-of-gs/

Include Transliteration plugin into core. This would need to be hooked/replaced 
into the to7bit() function.

Original issue reported on code.google.com by ccagle8 on 25 Apr 2011 at 6:32

GoogleCodeExporter commented 9 years ago
I am thoroughly confused looking at Zegnat's plugin. Here is the 
TRANSLITERATION plugin for reference so I don't have to keep downloading it:

function translit($t=false,$m=false) {
    global $i18n;
    if (is_array($a=$m)||is_array($a=@$i18n['TRANSLITERATION'])||is_array($a=@$i18n['TRANSLIT'])) {
        if (!$t&&isset($_POST['submitted'])) {
            global $url, $xml, $file;
            $t = ($u=$_POST['post-id'])?$u:($u=$_POST['post-title'])?$u:'temp';
            $url = clean_url(to7bit(str_replace(array_keys($a),array_values($a),$t)));
            unset($xml->url);
            $note = $xml->addChild('url');
            $note->addCData($url);
            $file = GSDATAPAGESPATH.$url.".xml";
            return true;
        }
        return str_replace(array_keys($a),array_values($a),$t);
    }
    else return false;
}

Original comment by ccagle8 on 27 Apr 2011 at 1:01

GoogleCodeExporter commented 9 years ago
on the language file side, this is an example of what is added (polish)

"TRANSLITERATION" => array(
  "Ą"=>"A","Ć"=>"C","Ę"=>"E",
  "Ł"=>"L","Ń"=>"N","Ó"=>"O",
  "Ś"=>"S","Ź"=>"Z","Ż"=>"Z",
  "ą"=>"a","ć"=>"c","ę"=>"e",
  "ł"=>"l","ń"=>"n","ó"=>"o",
  "ś"=>"s","ź"=>"z","ż"=>"z",
  "№"=>"#","—"=>"-","."=>"-",
  ","=>"-"
),

Original comment by ccagle8 on 27 Apr 2011 at 1:02

GoogleCodeExporter commented 9 years ago
First of all, the translit() function is a multi-purpose function. It is made 
to support all kinds of input. It is able to run from changedata.php as a 
plugin but the function can also be used by any other plugin.

You can provide translit() with a string and/or an array containing the 
transliteration (‘translit’ from now on) values. If no values are provided 
it assumes it’s being used as a plugin on changedata-save.

So how does all of this work?

The first if() statement is to figure out the array of translit values and to 
assign these to $a. It first checks for an array provided to the function as 
$m, if $m is not an array it will check your currently selected language file 
($i18n) for TRANSLITERATION and TRANSLIT values (in that order). If nothing is 
found the function directly returns false but if an array was found we move on.

The next step is to see if any text was provided in $t. If there is the 
function will return $t after doing a str_replace() on it with the translit 
values saved in $a.

If no text has been provided (!$t) it checks if the page is the result of a 
submit (isset($_POST['submitted'])). If this is the case it assumes we are 
running on changedata.php and gives itself access to a couple of extras.

It *tries* to undo everything GetSimple has done to the URL and then runs 
clean_url() and to7bit() itself. Different from GetSimple however the input it 
gives to to7bit() is after running the post-id/post-title through the translit 
table. Acting before to7bit() enables it to save as many characters as possible.

The next bit of XML trickery is needed to correctly overwrite the URL element 
as saved in $xml. It also needs to reassign the save path ($file) to make the 
file name match the newly created page URL.

Almost all the code currently used to modify the XML file before it is saved 
can be removed when this is merged with the core. The only thing important for 
the core is the if() statement to figure out where the translit values are 
coming from and the str_replace().

Sorry for walking you through the whole of the code when all you would need are 
2 lines ;-) We will need to agree on where translit values should be stored &c.

Original comment by martijn.personal@gmail.com on 1 May 2011 at 12:52

GoogleCodeExporter commented 9 years ago
well, i think the easiest would be to leave it where it currently is (LANG 
File)... or do we have enough transliteration arrays that we can successfully 
add them to the core?

Original comment by ccagle8 on 2 May 2011 at 12:03

GoogleCodeExporter commented 9 years ago
I think the language files will be the best way to go. There are at least as 
many arrays as there are alphabets.

One thing that might be an idea is to implement a plugin hook/filter that will 
allow people to modify the page ID at saving. The saving process uses the ID 
for a number of things and it’s impossible to undo all those actions once GS 
hits changedata-save. 

Changing the ID (or even stopping the save process) through a plugin needs to 
happen inside the if($_POST['post-id']) block.

I’m still very busy with school stuff and am still searching simple GUI-based 
SVN software for my MacBook so don’t expect any quick fix from me for this. 
If you want any help mail me and I’ll see what I can do.

Original comment by martijn.personal@gmail.com on 14 May 2011 at 3:29

GoogleCodeExporter commented 9 years ago
Basic transliteration is now possible by adding an array to the LANG file. The 
plugin supported both "TRANSLITERATION" and "TRANSLIT" as possible LANG items, 
the current (r499) implementation only supports "TRANSLITERATION".

I still think a filter will need to be added so plugins can tap into changing 
the slug of pages. Maybe a future addition.

Not labelling this as fixed, it needs bug testing still.

Original comment by martijn.personal@gmail.com on 14 Jun 2011 at 11:41

GoogleCodeExporter commented 9 years ago
yojoe tested the core fix and said it is working for his languages. Im going to 
close this and if any other transliteration issues popup, lets make a new issue.

Original comment by ccagle8 on 2 Jul 2011 at 12:40