Raised This Month: $51 Target: $400
 12% 

[ANY] Ex-Translations


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Why not
Junior Member
Join Date: Dec 2019
Old 03-17-2021 , 11:12   [ANY] Ex-Translations
Reply With Quote #1

Ex-Translations

This is an add-on for already available language features

Installation:
  1. Download the latest release for your OS version.
  2. Unpack to your server.

Feedback
Github-issue

Usage
PHP Code:

methodmap PhraseCollection 
Handle
{
    
// Creates a collection of plugin phrase files 
    //
    // The PhraseCollection must be freed via delete or CloseHandle().
    
public native PhraseCollection(Handle hPlugin);


    
// Retrieves the collection size.
    //
    // @return               Size.
    
public native int GetSize();


    
// Retrieves a PhraseFile object from the collection.
    //
    // @param   index       File index
    //
    // @return              Phrase file (must be freed)
    //
    // @error               Invalid handle or index        
    
public native PhraseFile GetFile(int index);


    
// Adding a new file to the plugin collection 
    // 
    // @param   filename    Translation filename (with out .txt extension)
    //
    // @noreturn
    //
    // @error               Invalid handle or file isn't exists?
    
public native void AddFile(const char[] filename);


    
// Retrieves an index of phrase file.
    //
    // @param   filename    Translation filename
    //
    // @return              Index or -1 if not found
    //
    // @error               Invalid handle
    
public native int FindFile(const char[] filename);
}

methodmap PhraseFile Handle
{
    
// Retrieves a phrase filename.
    //
    // @param   buffer      Buffer to store
    //
    // @noreturn
    //
    // @error               Invalid (parent/child)handle
    
public native void GetFilename(char[] bufferint size);


    
// Checks for the presence of a phrase in the current phrase file 
    //
    // @param   phrase      Phrase to check
    //
    // @return              true - exsits / false - otherwise
    //
    // @error               Invalid (parent/child)handle
    
public native bool TranslationPhraseExists(const char[] phrase);


    
// Is the file split by language 
    //
    // @return              true - splitted / false - otherwise
    //
    // @error               Invalid (parent/child)handle
    
public native bool IsSplitted();


    
// Retrieves the full path to the phrase file. 
    //
    // @param   lang        -1 if the file is not split, otherwise - language id 
    // @param   buffer      Buffer to store
    // @param   size        Buffer size
    //
    // @return              true - path exists / false - otherwise
    //
    // @error               Invalid (parent/child)handle / lang id
    
public native bool GetFilepath(int lang = -1char[] bufferint size);


    
// Exports a Phrases tree to a phrase file. 
    //
    // @param   kv          KeyValue tree
    // @param   path        Path to the phrase file
    //
    // @return              true - success/false - otherwise
    //
    // @error               Invalid (parent/child)handle
    
public bool ExportToFile(KeyValues kv, const char[] path)
    {
        
kv.Rewind();
        if(!
kv.GotoFirstSubKey())
        {
            return 
false;
        }

        
File hFile;
        if((
hFile OpenFile(path"w")) == null)
        {
            return 
false;
        }

        
char szBuffer[PLATFORM_MAX_PATH];
        
char szValue[PLATFORM_MAX_PATH];

        
hFile.WriteLine("\"Phrases\" \n{");

        do
        {
            
kv.GetSectionName(szBuffersizeof(szBuffer));
            
hFile.WriteLine("\t\"%s\" \n\t{"szBuffer);

            if(
kv.GotoFirstSubKey(false))
            {
                do
                {
                    
kv.GetSectionName(szBuffersizeof(szBuffer));
                    
kv.GetString(""szValuesizeof(szValue));

                    
hFile.WriteLine("\t\t\"%s\"\t\t\t\"%s\""szBufferszValue);

                } while(
kv.GotoNextKey(false));

                
kv.GoBack();
            }

            
hFile.WriteLine("\t}");

        } while(
kv.GotoNextKey());

        
hFile.WriteLine("}");

        
delete hFile;
        return 
true;
    }

    
// Imports a phrase file in KeyValues format
    //
    // @param   path        Path to the phrase file
    //
    // @return              KeyValue or null
    //
    // @error               Invalid (parent/child)handle
    
public KeyValues ImportFromFile(const char[] path)
    {
        
KeyValues kv;
        
kv = new KeyValues("Phrases");

        if(!
kv.ImportFromFile(path))
        {
            
delete kv;
        }

        return 
kv;
    }
}


/**
 *  Reparses all loaded translations files.
 */
native void RebuildLanguageDatabase(); 
Download: Releases
Why not is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 03-19-2021 , 08:01   Re: [ANY] Ex-Translations
Reply With Quote #2

Nice, but .. why? When would you use this? What is missing from the builtin translation system?
__________________
Peace-Maker is offline
Why not
Junior Member
Join Date: Dec 2019
Old 03-20-2021 , 02:48   Re: [ANY] Ex-Translations
Reply With Quote #3

Quote:
Originally Posted by Peace-Maker View Post
Nice, but .. why? When would you use this? What is missing from the builtin translation system?
Oh, I needed some features for this: https://youtu.be/_9eR7DzKTAI
Why not is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode