Translation is not displayed in the project

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Translation is not displayed in the project

#1 Post by Andredron »

Hello everyone, doing the translation I need to do there, so that when I move to the word - its meaning is highlighted

00resurse.rpy

Code: Select all


init python:

    lexicon = {
        (_('Okonomiyaki'),_( 'お好み焼き'))  : """
            Fried dough roll with cabbage with seafood, Japanese pizza.""",
        (_('Akashi-yaki'), _('明石焼き')) : """
            Batter rolls with octopus slices """
    }

    def hyperlink_lexicon( str_to_test ):

        for keys in lexicon:
        
            if isinstance(keys, basestring):
                keys = [keys]
        
            for phrase in keys:

                # preceded by a space
                str_to_test = str_to_test.replace(
                    " {0}".format(phrase),
                    " {{a=lexicon:{phrase}}}{phrase}{{/a}}".format(
                        phrase = phrase ) )
                
                # followed by a space
                str_to_test = str_to_test.replace(
                    "{0} ".format(phrase),
                    "{{a=lexicon:{phrase}}}{phrase}{{/a}} ".format(
                        phrase = phrase ) )
        
        return str_to_test

    config.say_menu_text_filter = hyperlink_lexicon


    def hyperlink_styler(*args):

        return style.hyperlink_text

    def hyperlink_hovered(*args):
        
        if not args[0]:
            # Ren'Py 7+ recent nightly only, see below
            renpy.hide_screen("lexicon_popup")
        
        elif args[0][:8] == "lexicon:":

            renpy.show_screen( "lexicon_popup", 
                               args[0][8:], 
                               renpy.get_mouse_pos() )
            
            renpy.restart_interaction()
        
        return

    def hyperlink_clicked(*args):

        if args[0] and args[0][:8] != 'lexicon:':

            # adapted from common/00defaults.rpy
            if args[0].startswith("http:") or args[0].startswith("https:"):
                try:
                    import webbrowser
                    webbrowser.open(args[0])
                except:
                    renpy.notify("Failed to open browser")

            elif args[0].startswith("jump:"):
                renpy.jump( args[0][5:] )

            else:
                renpy.call_in_new_context(args[0][args[0].index(':')+1:])

    
    style.default.hyperlink_functions = ( hyperlink_styler, 
                                          hyperlink_clicked, 
                                          hyperlink_hovered )


screen lexicon_popup(phrase=None, pos=(100,100)):

    if phrase:

        python:
            # get description
            d = [ lexicon[k] for k in lexicon if phrase in k ]
            description = d[0] if len(d) else "No description found."
            description = " ".join( [ k for k in description.split()
                                      if k not in [" ", "\t"] ] )
            
            # move the ypos up by a bit
            pos = ( pos[0], pos[1] - 25 )

            # reformat phrase
            p = [ k for k in lexicon if phrase in k ]
            primary_phrase = p[0][0] if len(p) else phrase
            if primary_phrase != phrase:
                phrase = "{0} ({1})".format(phrase, primary_phrase)

        frame:
            anchor (0.5, 1.0)
            pos pos
            xsize 340
            background Solid("#A9B")
            vbox:
                text "[phrase]" size 18
                text "[description]" size 14

    timer 4.0 action Hide("lexicon_popup")
Making a link to the words _( 'お好み焼き') and _('明石焼き') In the default translation, everything works as it should

script.rpy

Code: Select all

label start:
    scene black
    voice "voice/181.ogg"
    ha "慎二君はさ、お好み焼き と 明石焼き 、どっち派?"
Image

But when I generate a translation, my text is translated, but when I put a button on the keywords - the function does not respond

translation.rpy

Code: Select all

init -3 python:
    if persistent.lang is None:
        persistent.lang = "japan"


    lang = persistent.lang

init python:
    config.main_menu.insert(3, (u'Language', "language_chooser", "True"))


init python:

    if lang == "japan":
        style.default.font = "MTLc3m.ttf" #your font here
        
    elif lang == "russian":
        style.default.font = "open-sans.ttf" #your font here

tl/russia/00resurse.rpy

Code: Select all

# TODO: Translation updated at 2019-03-20 16:23
translate russian strings:

    # 00resurse.rpy:158
    old "Okonomiyaki"
    new "Okonomiyaki"

    # 00resurse.rpy:158
    old "お好み焼き"
    new "Окономияки"

    # 00resurse.rpy:158
    old "\n            Fried dough roll with cabbage with seafood, Japanese pizza."
    new "\n            Жареная лепёшка из теста с капустой с добавлением морепродуктов. Японская пицца"

    # 00resurse.rpy:158
    old "Akashi-yaki"
    new "Akashi-yaki"

    # 00resurse.rpy:158
    old "明石焼き"
    new "Акасияки"

    # 00resurse.rpy:158
    old "\n            Batter rolls with octopus slices "
    new "\n            Колобки из жидкого теста с кусочками осьминога"
and
tl/russia/script.rpy

Code: Select all

# TODO: Translation updated at 2019-03-20 16:23

# game/script4.rpy:765
translate russian festival_0623cd91:

    # voice "voice/181.ogg"
    # ha "慎二君はさ、お好み焼き と 明石焼き 、どっち派?"
    voice "voice/181.ogg"
    ha "Синдзи-кун, Окономияки или Акасияки , что будешь?"
Image

Tell me how to correctly mark the text, so that it would appear in the translation as in the original. Already tried everything, need this feature.

Help please

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Translation is not displayed in the project

#2 Post by Remix »

That old version wasn't really written for translation.

Try these tweaks (though I have Not tested the translation part much):

Code: Select all

init python:

    lexicon = {
        # ....
    }

    def hyperlink_lexicon( str_to_test ):

        for keys in lexicon:

            if isinstance(keys, basestring):
                keys = [keys]

            for phrase in keys:

                translated_phrase = renpy.substitutions.substitute( phrase )[0]

                # preceded by a space
                str_to_test = str_to_test.replace(
                    " {0}".format(translated_phrase),
                    " {{a=lexicon:{phrase}}}{translated_phrase}{{/a}}".format(
                        phrase = phrase,
                        translated_phrase = translated_phrase ) )

                # followed by a space
                str_to_test = str_to_test.replace(
                    "{0} ".format(translated_phrase),
                    "{{a=lexicon:{phrase}}}{translated_phrase}{{/a}} ".format(
                        phrase = phrase,
                        translated_phrase = translated_phrase ) )

        return str_to_test

    config.say_menu_text_filter = hyperlink_lexicon



screen lexicon_popup(phrase=None, pos=(100,100)):

    if phrase:

        python:

            # get description
            d = [ lexicon[k] for k in lexicon if phrase in k ]
            description = d[0] if len(d) \
                          else "No description found for phrase '{}'".format(phrase)

            description = renpy.substitutions.substitute( description )[0]

            description = " ".join( [ k for k in description.split()
                                      if k not in [" ", "\t"] ] )

            # move the ypos up by a bit
            pos = ( pos[0], pos[1] - 25 )

            # reformat phrase
            p = [ k for k in lexicon if phrase in k ]
            primary_phrase = p[0][0] if len(p) else phrase

            primary_phrase = renpy.substitutions.substitute( primary_phrase )[0]

            phrase = renpy.substitutions.substitute( phrase )[0]
            
            if primary_phrase != phrase:
                phrase = "{0} ({1})".format(phrase, primary_phrase)

        frame:
            anchor (0.5, 1.0)
            pos pos
            xsize 340
            background Solid("#A9B")
            vbox:
                text "[phrase]" size 18
                text "[description]" size 14
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Google [Bot]