Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Iavra Game Localization - Messages Module 1.00
- # -----------------------------------------------------------------------------
- # Description:
- # Adds a new message code that can be used to load localized messages.
- # -----------------------------------------------------------------------------
- # Prerequisites:
- # Iavra Game Localization - Core Engine
- # -----------------------------------------------------------------------------
- # How to Use:
- # Language files are built after the following format:
- #
- # {
- # :messages => {
- # :key => "Localized message"
- # }
- # }
- #
- # All message codes can be used, but backslashes need to be doubled.
- # -----------------------------------------------------------------------------
- # Terms of Use:
- # Free to use for both commercial and non-commercial games. Please give credit.
- # -----------------------------------------------------------------------------
- # Credits:
- # Iavra
- # -----------------------------------------------------------------------------
- # Changelog:
- # - 1.00: Release version.
- #==============================================================================
- ($imported ||= {})[:iavra_i18n_messages] = true
- fail "This module needs the core engine to function." unless $imported[:iavra_i18n_core]
- #==============================================================================
- # ▼ IAVRA::I18N::MESSAGES
- #==============================================================================
- module IAVRA
- module I18N
- module MESSAGES
- #========================================================================
- # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
- #========================================================================
- #========================================================================
- # The messagecode that should be replaces by localized messages. Can be
- # changed to avoid conflits with other scripts.
- #========================================================================
- MESSAGECODE = ":"
- #========================================================================
- # If true, localized messages can in turn include other messages. Be
- # careful to not create a loop, since it will cause your game to crash.
- # If this is false, message codes will instead be replaced by empty
- # string (other codes like \\v[1] will always work).
- #========================================================================
- SUB_INCLUDES = false
- #========================================================================
- # ■ ■ ■ ■ ■ CONFIGURATION ■ ■ ■ ■ ■
- #========================================================================
- #========================================================================
- # The category used inside language files to indicate messages.
- #========================================================================
- CATEGORY = :messages
- #========================================================================
- # Building the regex
- #========================================================================
- REGEX = /\\#{MESSAGECODE}\[(.+)\]/i
- #==========================================================================
- # Just a shorthand method.
- #==========================================================================
- def self.[](sym)
- IAVRA::I18N[CATEGORY][sym]
- end
- end
- end
- end
- #==============================================================================
- # ▼ Window_Base
- #==============================================================================
- class Window_Base < Window
- alias :iavra_i18n_messages_convert_escape_characters :convert_escape_characters
- #============================================================================
- # make sure to call our own convert method, too.
- #============================================================================
- def convert_escape_characters(text)
- result = iavra_i18n_messages_convert_messagecode(text)
- result = iavra_i18n_messages_convert_escape_characters(result)
- result
- end
- #============================================================================
- # Converts our messagecode to a localized messages.
- # If SUB_INCLUDES is set to true, this is done recursively. If not,
- # subincludes are replaced with empty strings, instead.
- #============================================================================
- def iavra_i18n_messages_convert_messagecode(text)
- text.gsub(IAVRA::I18N::MESSAGES::REGEX) {
- result = IAVRA::I18N::MESSAGES[$1.to_sym] || ""
- IAVRA::I18N::MESSAGES::SUB_INCLUDES ?
- iavra_i18n_messages_convert_messagecode(result) :
- result.gsub(IAVRA::I18N::MESSAGES::REGEX, "")
- }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement