A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS2 Translator

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    22

    AS2 Translator

    Okay so I have this script for my translator from Latin to Cyrillic alphabet.
    It works as expected,but what it doesn't do is when I want "dj" to turn into "ђ" it does every letter for itself..How can I make this work (just for these letters dj-ђ,lj-љ, nj-њ and dz-џ)?

    PHP Code:
    stop();

    bTranslate.onPress = function() 

            var 
    sInput tIn.text;
            
    sInput translate(sInput);
            
    tOut.text sInput;

    function 
    translate(sInput

    //абвгдђежзијклљмнњопрстћуфхцчџш
            
    sInput searchAndReplace(sInput"a""a"); 
            
    sInput searchAndReplace(sInput"b""б"); 
            
    sInput searchAndReplace(sInput"v""в"); 
            
    sInput searchAndReplace(sInput"g""г"); 
            
    sInput searchAndReplace(sInput"d""д"); 
            
    sInput searchAndReplace(sInput"đ""ђ"); 
            
    sInput searchAndReplace(sInput"dj""ђ"); 
            
    sInput searchAndReplace(sInput"e""е"); 
            
    sInput searchAndReplace(sInput"""ж"); 
            
    sInput searchAndReplace(sInput"z""з"); 
            
    sInput searchAndReplace(sInput"i""и"); 
            
    sInput searchAndReplace(sInput"j""ј"); 
            
    sInput searchAndReplace(sInput"k""к"); 
            
    sInput searchAndReplace(sInput"l""л"); 
            
    sInput searchAndReplace(sInput"lj""љ"); 
            
    sInput searchAndReplace(sInput"m""м"); 
            
    sInput searchAndReplace(sInput"n""н"); 
            
    sInput searchAndReplace(sInput"nj""њ"); 
            
    sInput searchAndReplace(sInput"o""о"); 
            
    sInput searchAndReplace(sInput"p""п"); 
            
    sInput searchAndReplace(sInput"r""р"); 
            
    sInput searchAndReplace(sInput"s""с"); 
            
    sInput searchAndReplace(sInput"t""т"); 
            
    sInput searchAndReplace(sInput"ć""ћ"); 
            
    sInput searchAndReplace(sInput"u""у"); 
            
    sInput searchAndReplace(sInput"f""ф"); 
            
    sInput searchAndReplace(sInput"h""х"); 
            
    sInput searchAndReplace(sInput"c""ц"); 
            
    sInput searchAndReplace(sInput"č""ч"); 
            
    sInput searchAndReplace(sInput"d""џ"); 
            
    sInput searchAndReplace(sInput"""ш"); 
            return 
    sInput

    function 
    searchAndReplace(abc

            
    tmp a.split(b);
            
    tmp.join(c);
            return (
    a);

    Thanks

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    It will work more efficiently if you put the double letter types first, like so below.
    It is probably not 100% fail proof as I do not know these languages and how often you use words with the double things.
    PHP Code:
    stop();

    bTranslate.onPress = function()
    {
        var 
    sInput tIn.text;
        
    sInput translate(sInput);
        
    tOut.text sInput;
    };
    function 
    translate(sInput)
    {
        
    //абвгдђежзијклљмнњопрстћуфхцчџш
        
    sInput searchAndReplace(sInput"dj""ђ");
        
    sInput searchAndReplace(sInput"nj""њ");
        
    sInput searchAndReplace(sInput"lj""љ");
        
    sInput searchAndReplace(sInput"dž""џ");
        
    sInput searchAndReplace(sInput"a""a");
        
    sInput searchAndReplace(sInput"b""б");
        
    sInput searchAndReplace(sInput"v""в");
        
    sInput searchAndReplace(sInput"g""г");
        
    sInput searchAndReplace(sInput"d""д");
        
    sInput searchAndReplace(sInput"đ""ђ");
        
    sInput searchAndReplace(sInput"e""е");
        
    sInput searchAndReplace(sInput"ž""ж");
        
    sInput searchAndReplace(sInput"z""з");
        
    sInput searchAndReplace(sInput"i""и");
        
    sInput searchAndReplace(sInput"j""ј");
        
    sInput searchAndReplace(sInput"k""к");
        
    sInput searchAndReplace(sInput"l""л");
        
    sInput searchAndReplace(sInput"m""м");
        
    sInput searchAndReplace(sInput"n""н");
        
    sInput searchAndReplace(sInput"o""о");
        
    sInput searchAndReplace(sInput"p""п");
        
    sInput searchAndReplace(sInput"r""р");
        
    sInput searchAndReplace(sInput"s""с");
        
    sInput searchAndReplace(sInput"t""т");
        
    sInput searchAndReplace(sInput"ć""ћ");
        
    sInput searchAndReplace(sInput"u""у");
        
    sInput searchAndReplace(sInput"f""ф");
        
    sInput searchAndReplace(sInput"h""х");
        
    sInput searchAndReplace(sInput"c""ц");
        
    sInput searchAndReplace(sInput"č""ч");
        
    sInput searchAndReplace(sInput"š""ш");
        return 
    sInput;
    }
    function 
    searchAndReplace(abc)
    {
        
    tmp a.split(b);
        
    tmp.join(c);
        return (
    a);

    and of cousre embed the fonts
    Last edited by fruitbeard; 12-05-2012 at 02:20 AM. Reason: Font embed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center