Multiple Sources with different count of languages

More
6 years 8 months ago - 6 years 8 months ago #2937 by Ligrew
I'd like to have 2 language sources:
- first one for texts with 8 languages
- second one for audio with only 2 languages

Is it possible to achieve this? If yes, how should I do that?
How to change language per source and get localization from specific source?
Last edit: 6 years 8 months ago by Ligrew.

Please Log in or Create an account to join the conversation.

More
6 years 8 months ago #2951 by Frank
Hi,
Yes, you can have more than 1 language source.

There are several ways of doing this.
1- You can have several Global language sources.

Global Language sources (e.g. I2Languages.prefab) are prefabs that are automatically loaded by the game and used in any scene.
To add another source, just duplicate the I2Languages.prefab (e.g. ExtraLanguages.prefab) and add its name to the GlobalSources array in:
Assets\I2\Localization\Scripts\Manager\LocalizationManager_Sources.cs line 16
public static string[] GlobalSources = { "I2Languages" , "ExtraLanguages" };

Each source can have different languages and terms.

2- Have the general terms in I2Languages.prefab, and load Local Sources that are only used in some scenes.
This is the approach used by the Example scenes.
Local Sources are GameObjects in your scene that have a LanguageSource component. And there you define terms/languages that are only used in that scene.

That makes easy to add them to assetBundles and lower your memory if your game has a huge amount of languages/texts.


Hope that helps,
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out

Please Log in or Create an account to join the conversation.

More
6 years 8 months ago - 6 years 7 months ago #2961 by Ligrew
Hi,

Thanks for your response. I need only one Global source for subtitles.
I managed to copy it, disconnect from Google spreadsheet, than remove some of unnecessary terms (not all terms has its corresponding audio file) and for the rest changed Type to AudioClip using this code:
for (int i = 0; i < source.mTerms.Count; i++)
    source.mTerms[i].TermType = eTermType.AudioClip;
and set source as dirty in EditorUtilities.

To add audio clips to corresponding terms I did something like this:
    public void FindAsset()
    {
        if (source)
        {
            source.Assets.Clear();

            for (int i = 0; i < source.mTerms.Count; i++)
            {
                string assetName = source.mTerms[i].Term;
                assetName = assetName.Substring(assetName.LastIndexOf("/") + 1);

                string[] results = AssetDatabase.FindAssets(assetName);
                string res = "";

                foreach (string guid in results)
                {
                    AddAsset(FindAsset(res = AssetDatabase.GUIDToAssetPath(guid), "ACTORS_VO/"), i, 0);
                    AddAsset(FindAsset(res, "ACTORS_VO_PL/"), i, 1);
                }
            }
        }
    }

    protected void AddAsset(Object obj, int ind, int lang)
    {
        if (obj)
        {
            source.AddAsset(obj);
            source.mTerms[ind].Languages_[lang] = obj.name;
        }
    }

    protected Object FindAsset(string org, string comp)
    {
        if (org.Contains(comp))
        {
            Object obj = AssetDatabase.LoadAssetAtPath(org, typeof(AudioClip));

            if (obj)
                return obj;
            else
                return null;
        }

        return null;
    }
and set source as dirty as well. Everything seems to work ok, have no empty language field

The weird thing is that when I start game, in every single term field: mTerm[x].Languages[0] is set to "None (Audio Clip)" and I have no idea where and why?

This is the code responsible for changing language in that source:
        public void SetAudioLanguage(string language)
        {
            var iCurrentLang = sourceAudio.GetLanguageIndex(language, true, false);
            sourceAudio.LoadLanguage(iCurrentLang, true, true, true, true);
        }

In fact what I need is LanguageSource, that is not global and that doesn't care about global Language.
Any suggestions?
Last edit: 6 years 7 months ago by Ligrew.

Please Log in or Create an account to join the conversation.

More
6 years 7 months ago #2993 by Ligrew
Any solution on this one?

Please Log in or Create an account to join the conversation.

More
6 years 7 months ago #2995 by Frank
Are all your audioclips in a Resources folder?
The plugin can only load them at runtime if they are in a resource folder.

The other alternative (if they are not in the Resources folder), is to add a reference to them. You can do that, by adding them to the Assets list inside the source, and then call UpdateAssetsDictionary()
inter-illusion.com/assets/I2LocalizationManual/AssetsTab.html

Also, if they are in the Resources folder, but inside a subfolder (e.g. "Asset\Resources\Audio"), then the translation needs to include its path: "Audio\name" instead of just "name'.

Hope that helps,
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out

Please Log in or Create an account to join the conversation.

Time to create page: 0.176 seconds
Template by JoomlaShine