Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: [1] 2 3

Author Topic: [MOD] Generating readable SEF urls for local language (sNews 1.5)  (Read 9837 times)

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955

If Your site is in english You don't need even look into this ;) For others it might be of some interest.

In this thread (look in posts) following languages are covered:
 - Latvian
 - Turkish (by courtesy of selcukhoca)
 - Greek (by courtesy of reanimator)
 - Swedish (by courtesy of agentsmith)
 - Spanish and Catalan (by courtesy of bramsyuur)
 - French (by courtesy of Sven)
 - German (by courtesy of reallySimple)
 - Slovak and Czech (by courtesy of oniip)

When I was creating articles in local language - generated urls were messy - as all language specific characters were simply thrown away. For example, if article is called 'Grāvī grūti' the default sef will look like 'grv-grti' - not so easy to read and use. And there is need to keep those sef unique as well.

After applying this mod on sNews javascripts, for same 'Grāvī grūti' title following sef will be built by default : 'gravi-gruti'. While not exactly original title - this is still readable and easier to use.

This mod requires following changes in javascript function genSEF() located at js() (end of snews.php):
Code: [Select]
// generate SEF urls
function genSEF(from,to) {
if (allowsef == true) {
// MOD - 20070106 - Replaces characters specific to local language with available lowercase equivalent
// Original code
// var str = str.toLowerCase();
var str = deLocalize(from.value);
str = str.toLowerCase();
// End of MOD - 20070106 - Replaces characters specific to local language with available lowercase equivalent
//str = str.replace(/[^a-zA-Z 0-9]+/g,'');
str = str.replace(/[^a-z 0-9]+/g,'');
str = str.replace(/\s+/g, "-");
to.value = str;
}
}
and introduction of new javascript function deLocalize() right after genSEF (example here is for latvian):
Code: [Select]
    // MOD - 20070106 - New function to replace characters specific to local language with available lowercase equivalent
// Deal with local characters (latvian)
function deLocalize( inStr ) {
var outStr = inStr;
outStr = outStr.replace(/[āĀ]/g, 'a');
outStr = outStr.replace(/[čČ]/g, 'c');
outStr = outStr.replace(/[ēĒ]/g, 'e');
outStr = outStr.replace(/[ģĢ]/g, 'g');
outStr = outStr.replace(/[īĪ]/g, 'i');
outStr = outStr.replace(/[ķĶ]/g, 'k');
outStr = outStr.replace(/[ļĻ]/g, 'l');
outStr = outStr.replace(/[ņŅ]/g, 'n');
outStr = outStr.replace(/[šŠ]/g, 's');
outStr = outStr.replace(/[ūŪ]/g, 'u');
outStr = outStr.replace(/[žŽ]/g, 'z');
return outStr;
}
// End of MOD - 20070106 - New function to replace characters specific to local language with available lowercase equivalent
After applying this generated urls were at least readable if a little misspelled  :) 
Modified script is used in administration part of sNews - so no public access demo for now.

For other languages deLocalize() should be tweaked accordingly ;)

May be those, who find this mod handy can post their deLocalize()  versions here, so others can reuse them as well :D
« Last Edit: September 24, 2007, 12:12:42 PM by codetwist »
Logged

Mika

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 9
  • Posts: 1408
    • http://www.ni5ni6.com/
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #1 on: January 06, 2007, 06:18:23 AM »

Nice job, mate :) ... and your post goes to Mods section ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #2 on: January 06, 2007, 09:14:17 AM »

Whoa ... my first 'official' MOD  :cool:
« Last Edit: September 24, 2007, 12:13:11 PM by codetwist »
Logged

selcukhoca

  • Newbie
  • *
  • Karma: 0
  • Posts: 7
    • http://www.selcukhoca.com/snewstr/
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #3 on: April 29, 2007, 09:32:35 PM »

Yes very nice Mode .
in turkish second part like this :

 
Code: [Select]
function deLocalize( inStr ) {
        var outStr = inStr;
        outStr = outStr.replace(/[çÇ]/g, 'c');
        outStr = outStr.replace(/[ğĞ]/g, 'g');
        outStr = outStr.replace(/[ıI]/g, 'i');
        outStr = outStr.replace(/[öÖ]/g, 'o');
        outStr = outStr.replace(/[şŞ]/g, 's');
        outStr = outStr.replace(/[üÜ]/g, 'u');
         return outStr;
    }
Logged

bramsyuur

  • sNews Dude
  • Hero Member
  • *****
  • Karma: 23
  • Posts: 900
    • http://snews.vietbee.net
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #4 on: April 30, 2007, 08:10:31 PM »

@Codetwist:
This is a great mod addition. Thanks for sharing it.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #5 on: May 01, 2007, 11:15:25 AM »

Thanks, selcukhoca and bramsyuur ;)

May be all of those, who find this mod handy can post their deLocalize()  versions here, so others can reuse them as well :D
Logged

reanimator

  • Newbie
  • *
  • Karma: 0
  • Posts: 31
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #6 on: May 02, 2007, 01:55:31 PM »

Greek:

Quote
function deLocalize( inStr ) {
var outStr = inStr;
outStr = outStr.replace(/[άΆαΑ]/g, 'a');
outStr = outStr.replace(/[βΒ]/g, 'b');
outStr = outStr.replace(/[γΓ]/g, 'g');
outStr = outStr.replace(/[δΔ]/g, 'd');
outStr = outStr.replace(/[έΈεΕ]/g, 'e');
outStr = outStr.replace(/[ζΖ]/g, 'z');
outStr = outStr.replace(/[ήΉηΗ]/g, 'i');
outStr = outStr.replace(/[θΘ]/g, 'th');
outStr = outStr.replace(/[ίΊιΙ]/g, 'i');
outStr = outStr.replace(/[κΚ]/g, 'k');
outStr = outStr.replace(/[λΛ]/g, 'l');
outStr = outStr.replace(/[μΜ]/g, 'm');
outStr = outStr.replace(/[νΝ]/g, 'n');
outStr = outStr.replace(/[ξΞ]/g, 'x');
outStr = outStr.replace(/[όΌοΟ]/g, 'o');
outStr = outStr.replace(/[πΠ]/g, 'p');
outStr = outStr.replace(/[ρΡ]/g, 'r');
outStr = outStr.replace(/[σΣ]/g, 's');
outStr = outStr.replace(/[τΤ]/g, 't');
outStr = outStr.replace(/[ύΎυΥ]/g, 'y');
outStr = outStr.replace(/[φΦ]/g, 'f');
outStr = outStr.replace(/[χΧ]/g, 'ch');
outStr = outStr.replace(/[ψΨ]/g, 'ps');
outStr = outStr.replace(/[ώΏωΩ]/g, 'o');

return outStr;
}
Logged

Fred K

  • Still trying to learn stuff
  • sNews Dude
  • ULTIMATE member
  • *****
  • Karma: 131
  • Posts: 2782
    • Personal
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #7 on: May 02, 2007, 03:46:39 PM »

Good mod. Now in Swedish as well. ;)

Quote from: Swedish
function deLocalize( inStr ) {
        var outStr = inStr;
        outStr = outStr.replace(/[åÅ]/g, 'aa');
        outStr = outStr.replace(/[äÄ]/g, 'ae');
        outStr = outStr.replace(/[öÖ]/g, 'oe');
        return outStr;
    }
Logged

bramsyuur

  • sNews Dude
  • Hero Member
  • *****
  • Karma: 23
  • Posts: 900
    • http://snews.vietbee.net
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #8 on: May 02, 2007, 08:21:47 PM »

Thanks Codetwist, here's my addition...
Well, this is for Spanish and Catalan language variants... all-in-one :)
Quote from: Spanish and Catalan
function deLocalize( inStr ) {
        var outStr = inStr;
        outStr = outStr.replace(/[çÇ]/g, 'c');
        outStr = outStr.replace(/[üÜ]/g, 'u');
        outStr = outStr.replace(/[ïÏ]/g, 'i');
        outStr = outStr.replace(/[áÁ]/g, 'a');
        outStr = outStr.replace(/[àÀ]/g, 'a');
        outStr = outStr.replace(/[éÉ]/g, 'e');
        outStr = outStr.replace(/[èÈ]/g, 'e');
        outStr = outStr.replace(/[íÍ]/g, 'i');
        outStr = outStr.replace(/[óÓ]/g, 'o');
        outStr = outStr.replace(/[òÒ]/g, 'o');
        outStr = outStr.replace(/[úÚ]/g, 'u');
        return outStr;
    }
I've missed the "Spain Catalan variant with miccle-dot L" l·l or L·L. I'll try how to do this...
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

tobto

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 72
    • seo service
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #9 on: May 03, 2007, 10:01:40 PM »

can you show some real sites of using it?
transliteration?
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #10 on: May 05, 2007, 11:28:52 AM »

Thanks reanimator, agentsmith and bramsyuur for code ;)

@tobto : This script is invoked in administration interface of sNews; so, no 'public' demo for this now ;) And anyway, in public part You can't tell a difference if particular article sef in url is tweaked by manual typing or by this mod.
Logged

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #11 on: May 05, 2007, 12:02:24 PM »

Hello
the french one :
Code: [Select]
function deLocalize( inStr ) {
var outStr = inStr;
outStr = outStr.replace(/[àÀ]/g, 'a');
outStr = outStr.replace(/[âÂ]/g, 'a');
outStr = outStr.replace(/[éÉ]/g, 'e');
outStr = outStr.replace(/[èÈ]/g, 'e');
outStr = outStr.replace(/[êÊ]/g, 'e');
outStr = outStr.replace(/[îÎ]/g, 'i');
outStr = outStr.replace(/[ôÔ]/g, 'o');
outStr = outStr.replace(/[ùÙ]/g, 'u');
outStr = outStr.replace(/[üÜ]/g, 'u');
 return outStr;
    }

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #12 on: May 05, 2007, 12:11:01 PM »

Thanks, Sven ;)

Keep them coming, people :D
Logged

mike1

  • Full Member
  • ***
  • Karma: 6
  • Posts: 205
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #13 on: May 05, 2007, 04:01:37 PM »

should this also be in translations?
Logged

Sven

  • Dev Invitee
  • ULTIMATE member
  • *****
  • Karma: 88
  • Posts: 2069
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
[MOD] Generating readable SEF urls for local language (sNews 1.5)
« Reply #14 on: May 06, 2007, 08:51:29 AM »

no no mike, just at the bottom of the snews file in // JAVASCRIPT FUNCTIONS
but it doesn't work for me in any language (I just checked this very morning)
Pages: [1] 2 3