Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by hollym16 · Jun 15, 2016 at 01:04 PM · c#scenestringvaluelanguage

function based on return value

I've got a project set up the translates text to multiple languages by selecting a language in the first scene.

I want to expand on this by also adding voice overs in the correct language.

I need something along the lines of: get current language. if language = English, Play("EnglishVoiceOver.mp3");

Below is the piece of code that selects the language by referencing a CSV file:

 public static bool SelectLanguage(string alanguage)
     {
         currentLanguageIndex = -1;
         for(int i = 0; i < AvailableLanguages.Length; ++i)
             if (AvailableLanguages[i] == alanguage)
             {
                 currentLanguageIndex = i;
                 break;
             }
     
         if (Application.isPlaying)
         {
             if(LocalizationChanged != null)
                 LocalizationChanged();
         }
     
         return currentLanguageIndex >= 0;
     }
 
     public static string Get(string key)
     {
         string[] vals;
 
         if (currentLanguageIndex != -1 && dictionary.TryGetValue(key, out vals))
         {
             if (currentLanguageIndex < vals.Length)
                 return vals[currentLanguageIndex];
         }

Can anyone give me any ideas please?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by EpiFouloux · Jun 15, 2016 at 01:43 PM

Ideas about what, it's not really clear.. I think you're question is about how to save the language and apply it every time you need it:

Just set a int variable (static if you want) as the language (you did it, it's currentLanguageIndex)

then every time you need to play a sound or write a text :

 public class Example
 {
    private String[] welcome_texts = 
     {
         "Welcome",
         "Bienvenue",
          "Bienvenido"
     };
 
    void print_welcome()
    {
       print(welcome[Language.currentLanguageIndex]);
    }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by YasanthaPrabath · Jun 15, 2016 at 02:08 PM

How about you saving the file name of the vo along with text Id( key ) and depend on the key load the Audio files from Resources folder on run time and play. You put VO files on different folders according to language.

simple class structure from top of my head,

public enum LocaliseLanguage { English,Italian }

 class LocalizeSentence
 {
  string TextId;
  string LocalizedText;
  string VOFileName;
 }
 
 public class LocalizeSentenses
 {
    public LocaliseLanguage MyLanguage;
    List<LocalizeSentence>    LocalizeSentence;
 
   public string GetText( string Id )
   {
   // search given id and return LocalizedText
   }
 
   public string GetVOFileName()
   {
    // search given id and return VOFileName
   }
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hollym16 · Jun 15, 2016 at 03:29 PM 0
Share

Hi, Thanks for the reply.

This looks like the right direction but I'm still a bit confused, I get the concept but unsure how to apply it correctly.

Any chance you could elaborate a little, please?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

154 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get the active/loaded Scene then turn the name of it into a string? [C#] 1 Answer

List of Structs variable values not changing 1 Answer

Do Something If Temperature Reading Changes 0 Answers

Accessing a non-static string variable in another script C# 1 Answer

How to make a main menu like that ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges