GithubHelp home page GithubHelp logo

agens-no / polyglotunity Goto Github PK

View Code? Open in Web Editor NEW
302.0 13.0 40.0 1.19 MB

A Polyglot Localization plugin for Unity3d that translates games to many languages

Home Page: http://bit.ly/1ESPiO6

License: MIT License

C# 100.00%

polyglotunity's Introduction

PolyglotUnity

[]

A Unity3d plugin for Polyglot Localization, which is a project that translates games to many languages. This plugin makes it possible to automatically download the polyglot master spreadsheet and a custom game specific spreadsheet and parses it in a unity project.

https://docs.google.com/spreadsheets/d/17f0dQawb-s_Fd7DHgmVvJoEGDMH_yoSd8EYigrb0zmM/

Unity Version

Works with Unity 4.x, 5.x, 2017.x and 2018.x

Tested with several Unity Versions

  • Unity 5.4.4f1
  • Unity 5.5.2f1
  • Unity 5.6.0f3
  • Unity 5.6.1f1
  • Unity 2017.1.0b1
  • Unity 2017.2.0f3
  • Unity 2017.2.0p2
  • Unity 2017.3.0b10
  • Unity 2018.2.2f1
  • Unity 2018.2.5f1
  • Unity 2018.2.9f1
  • Unity 2018.3
  • Unity 2018.4
  • Unity 2019.1
  • Unity 2019.2
  • Unity 2019.3

Feedback

We would 😍 to hear your opinion about this library. Please file an issue if there's something you would like to see improved.

If you use this library and are happy with it consider sending out a tweet mentioning @agens. This library is made with love by Skjalg S. Mæhre.

(http://agens.no/)

First, you need to Configurate the Localization.

You do this by selecting the Configurate menu item from within Unity. This will create the Localization asset for you if it is not set up yet and then select it.

alt tag

Then you can specify the localization settings for the project.

alt tag

Finally you can add Localized Text components to your Text objects

alt tag

Theres also a Language Dropdown script that automatically populates a Dropdown with the available languages

alt tag

Create your own custom spreadsheet

Duplicate the polyglot master sheet and remove all the keys from line 7. The importer parses everything line after the term "polyglot", "PolyMaster" or "BEGIN".

alt tag

Add Sheet and docs id to the Localization Configuration

alt tag

Current Features

  • Download latest polyglot master sheet as CSV or TSV
  • Download a custom localization sheet as CSV or TSV
    • If you use the same keys as the master sheet your keys will override the master sheet.
  • Import the downloaded file and parse it
    • The sheet is parsed every time you play the game so you can iterate fast.
    • Can also be set to downloaded and parsed every time you play the game (optional)
  • Managing localizations
    • Specify any number of csv or tsv files to parse
    • Select language
    • Select fallback language if the localization key does not exist in the currently selected language
    • Invokes event when language is changed
  • Script for localizing UGUI Text component, TextMesh component and TextMesh Pro UGUI component
    • Auto completes localization key
    • Updates text and alignment of text (hebrew and arabic is left to right).
    • Supports parameters for localized strings such as "No {0} Selected".
  • Script for saving selected language
    • Saves to PlayerPrefs
  • TextMesh Pro support
  • Arabic font type support

Additional info for TextMeshPro integration

To use Polyglot with TextMeshPro from the Unity Package Manager (upm) you will need to add the dependency manually to the assembly definition files.

Versions tested:

  • Unity 2018.1.3f1
  • TextMeshPro 1.2.3 (from upm)

Open PolyglotScripts.asmdef and PolyglotEditor.asmdef in a text editor and manually add the dependency to Unity.TextMeshPro.

Your files should look like this:

PolyglotScripts.asmdef

{
    "name": "Polyglot.Scripts",
    "references": ["Unity.TextMeshPro"],
    "optionalUnityReferences": [],
    "includePlatforms": [],
    "excludePlatforms": [],
    "allowUnsafeCode": false
}

PolyglotEditor.asmdef

{
    "name": "Polyglot.Editor",
    "references": [
        "Polyglot.Scripts",
        "Unity.TextMeshPro"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": []
}

This makes the scripts find the dependency of TextMeshPro.

polyglotunity's People

Contributors

alexisdrain avatar biodam avatar johannesdeml avatar lawendt avatar skjalgsm avatar skjalgsm-statespace avatar spassvogel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polyglotunity's Issues

How to add a new language?

Hi!

I've been using polyglot for a while, and I LOVE this tool, it's crazy useful. Now, I want to add a new language that it's not included in the default languages (Galician, from Spain), but I don't know how. I have added it to the enum "Languages" but it does weird things.

Is there an easy way?

Thanks!
Carlos

is this repo still active?

Awesome project you guys have made, but it seems like nobody maintain this project any more, issues and pr exists for long time, I used PolyglotUnity in my game and I really like it, I have fixed some bugs and added some features for it, so if you guys still maintain this repo, I'd like to pull some requests, or I want to fork this repo to maintain this great plugin by myself and continue making it better, hope for your reply.

Right aligned text

I have some (English) text in a Text Component that has a LocalizedText. However, when the text gets translated, it automatically gets aligned to the left because of protected override void UpdateAlignment(Text text, LanguageDirection direction) ...

I would like to see an option on LocalizedText to maintain the original text alignment. Do you accept pull requests?

Multiline Support

When using line breaks in the spreadsheet they can be exported with csv. Sadly the parser is not capable of handling that. We would either need to rewrite the parser or use an established parser to get the job done properly. As for the external parser, I found https://github.com/joshclose/csvhelper

If we want to rewrite the existing parser, we would need to check for each '\n' and ',' if it is in between quotes. Not quite sure if there is an elegant version of doing that, but I think it might become a bit tricky to do it completely properly without creating too much overhead.

Any thoughts which road we should head down?

in script usage

Hi,
if is possible use this plugin from script can you write some docs?

Missing Languages in New Polyglot Update.

Polyglot was very recently updated where a new Master sheet was added.
https://docs.google.com/spreadsheets/d/17f0dQawb-s_Fd7DHgmVvJoEGDMH_yoSd8EYigrb0zmM/edit#gid=423963190

In my opinion, this will require changes in this repo:

A) In "LocalizationEditor.cs", the new default gid number should be changed from "296134756" to "423963190". The old number will download "Master_Old" and the new number will download "Master".

B) A few changes in "Langage.cs" are required in my opinion: "Language.cs" is not showing all the new languages in the correct order. This causes issues in "LocalizationImporter.cs". See 1-to-3 below:

  1. Selecting the second-to-last language, "Arabic," gives an error because it is listed as number 28. Arabic should be ordered to be number 26, coming right after Hebrew. After doing this minor change, Arabic will become selectable in my tests.

  2. Malay and Indonesian have been removed or renamed from the master sheet (?)

  3. The last language in the new Master sheet, "Bosnian," is missing and unselectable in the "supported languages." I don't know how to fix this because I don't know what the correct equivalent for "SystemLanguage.Bosnian".

C) (extra) Update the repo to Unity 2017.2

PS. Correct me if I'm wrong about any of the above information. I've only looked at this project today, and I don't know the contribution policy for this plug-in.

Automation suggestions

Hi, I have some suggestions for some tasks that could be automated to improve usability.

  1. Add the custom sheet TextAsset to the input files in the first download
  2. Parse the custom sheet after the download is complete
  3. Change the text in the UI.Text/TMP.Text component when changing the key in the localization script

Google Download doesn't work in older Unity versions like 5.6

The download from Google sheet functionality doesn't work for me in Unity 5.6, either with the master sheet or the custom sheet. The progress never goes beyond 0. It does work in Unity 2018.3.

Canceling the progress bar for some reason doesn't work so I had to force quit Unity for every attempt. To address this I added some timeout code.

        float lastProgress = 0;
        System.DateTime lastProgressTime = System.DateTime.Now;
        while (!www.isDone)
        {
            #if UNITY_5_5_OR_NEWER
            var progress = www.downloadProgress;
            #else
            var progress = www.progress;
            #endif
            if (progressbar != null && progressbar(progress))
            {
                done(null);
                yield break;
            }

            if (progress > lastProgress)
            {
                lastProgress = progress;
                lastProgressTime = System.DateTime.Now;
            }
            if ((System.DateTime.Now - lastProgressTime).TotalSeconds > 10)
            {
                Debug.LogError("Google sheet timed out.\nURL:" + url);
                done(null);
                yield break;
            }

            yield return null;
        }

Furthermore, to make the progress bar go away when an error happens, I had to add a EditorUtility.ClearProgressBar(); call in the DownloadComplete method in LocalizationEditor.cs.

However, these progress bar workarounds don't address the core issue that the localization data can't be downloaded in the first place.

LocalizedTextComponent.AddParameter(..) does not work for strings with more than 1 parameter

In the LocalizedTextComponent, the methods to add parameters AddParameter(..) triggers an error - FormatException - if the given string to format requires more than 1 parameter.

This is because every time a parameter is added via these methods, it will call OnLocalize() and thus try to format the string with the first added parameter. And currently the API does not contain a method to add a set of parameters at once.

As an example:

  • I have the localized string: Hello, my name is {0} and I work as {1}
  • Then by calling AddParameter("Bob"), it will trigger the FormatException error as it will immediately try to format the string.

As a workaround I added a method SetParameters(params object[] parameters) in the LocalizedTextComponent:

public void SetParameters(params object[] parameters) {
  ClearParameters();
  this.parameters.AddRange(parameters);
  OnLocalize();
}

Could this method be an alternative to the AddParameter() methods?

Readme Instructions - 'line 7'

Hey there, great tool & great spreadsheet. I have a quick query about the README.

I've copied & duplicated the sheet, but the following line is confusing me:

Duplicate the polyglot master sheet and remove all the keys from line 7. The importer parses everything line after the term "polyglot", "PolyMaster" or "BEGIN".

Do you mean 'line 6'? Or do I need to leave in 'polyglot' so it begins parsing after that?

image

(I'm sure I'll have an answer after actually testing it - however, just posting this here so I can refer back to it & request to update the README if necessary)

Missing reference to TextMeshPro package Unity 2018

Hello

First of all your asset seems to work pretty well.

I just found a bug with the TextMeshPro integration.

When I try to use Polyglot with TextMeshPro from the Unity Package Manager (upm) I got the following error e many different scripts:
Assets/Polyglot/Scripts/LocalizedTextMeshPro.cs(3,7): error CS0246: The type or namespace name `TMPro' could not be found. Are you missing an assembly reference?

My friend (@Lawendt) discovered this link that suggested the solution.

Open PolyglotScripts.asmdef and PolyglotEditor.asmdef in a text editor and manually add the dependency to Unity.TextMeshPro.

Your files should look like this:
PolyglotScripts.asmdef

{
    "name": "Polyglot.Scripts",
    "references": ["Unity.TextMeshPro"],
    "optionalUnityReferences": [],
    "includePlatforms": [],
    "excludePlatforms": [],
    "allowUnsafeCode": false
}

PolyglotEditor.asmdef

{
    "name": "Polyglot.Editor",
    "references": [
        "Polyglot.Scripts",
        "Unity.TextMeshPro"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": []
}

This makes the scripts find the dependency of TextMeshPro and everything seems to be working fine.

Someone in the forum said that the assembly definition file will provide a way to add dependencies to unity packages (from upm) through the editor, for now, the solution is to manually add it.

Unity 2018.1.3f1
TextMeshPro 1.2.3 (from upm)

Better documentation on integration for Custom Sheet

Hello, I am really enjoying this plugin for localisation! Thank you very much for it!

However, I struggled to get it up and running with a custom localisation file. It would be great to have better documentation about it, as I had to debug the code to understand how the formats and requirements for the localisation file are.

As I wish for new developers to have an easier time when integrating this tool, I would suggest to:

  1. Explain the required format for the localisation spreadsheet: localisation strings are only parsed after a row that start with "Polyglot"/"PolyMaster"/"BEGIN".
  2. Explain the the parsing ends when it meets a row that starts with "END".
  3. Explain that the custom spreadsheet needs to follow the same number and order of localised languages columns as the master sheet (plugin code relies on Languages enum's int numbers to fetch the language).
  4. Provide a template of a localisation spreadsheet that new developers can start from.
  5. Explain that the custom sheet needs to be a publicly available Google Spreadsheet so it can be downloaded via the Editor tool.

Handling of Selected Language with ScriptableObject

Hello,

When changing the selected language via code, I am using (e.g.) Localization.SelectedLanguage = Language.Dutch. This has a caveat as is it will change the serialized field selectedLanguage in the Localization ScriptableObject. This can cause some difficulties in the Unity Editor when working in a team and everyone starts seeing changes to this file.

Is this the correct way to change the selected language in run-time? If so, could a separate approach be considered for the selected language? (ie, do not set the serialized field but another cached field instead?)

Adding Arabic support in Unity Projects

I have translated the Polyglot master sheet to Arabic, but there is a severe issue that needs to be addressed in order to use this language in Unity.

Arabic is a cursive language where the letters in every word are connected to each other using alternative font characters. Unity, however, doesn't recognize that use-case and the Arabic words are split up and illegible. This can be fixed using a free store asset called "Arabic Support" also licensed under MIT like "PolyglotUnity".

It is found here:
https://www.assetstore.unity3d.com/en/#!/content/2674
https://github.com/Konash/arabic-support-unity

In order to fix the Arabic language for "PolyglotUnity", here are my suggested changes to this repo:

A) Put the file "Arabic Support > ArabicSupport.dll" into this repo.

B) In "PolyglotUnity > LocalizedText.cs > SetText()", add an if condition for Arabic:

protected override void SetText(Text text, string value) {
    if (text == null) {
        Debug.LogWarning("Missing text component for " + this, this);
        return;
    }
    if (Localization.Instance.SelectedLanguage == Language.Arabic) {
	text.text = ArabicFixer.Fix(value, true, true);
    } else {
        text.text = value;
    }
}

Here is the result (Before & after):
sprite-0007

Of course, I believe this should be done with the approval of the author of "Arabic Support" @Konash and the maintainers of this repo.

Error after Import: Assets/Polyglot/Editor/LocalizationEditor.cs(226,17): error CS1061: Type `UnityEngine.Networking.UnityWebRequest' does not contain a definition for `SendWebRequest' and no extension method `SendWebRequest' of type `UnityEngine.Networking.UnityWebRequest' could be found. Are you missing an assembly reference?

Hi,

I imported the Asset Folder contents into my 2017.1.1f1 project and am getting the following Error now:
Assets/Polyglot/Editor/LocalizationEditor.cs(226,17): error CS1061: TypeUnityEngine.Networking.UnityWebRequest' does not contain a definition for SendWebRequest' and no extension method SendWebRequest' of type UnityEngine.Networking.UnityWebRequest' could be found. Are you missing an assembly reference?

Indeed, the Class UnityWebRequest does not contain mentioned Method

Also, could you clarify the install instrucions a bit? There are the project files as well as 2 unity packages. What is the correct install procedure?

Thank you, this tool looks really awesome!

Checks for start and end of parsing

I just had the problem that my localization filw was not parsed anymore, even though I just added three simple strings to the file. After quite a while I found the problem: One added ID was "ENDSCREEN_BUTTON", which triggered if(key.StartsWith("END")) in LocalizationImporter.cs.

I think another convention than checking if the string starts with END would be benefitial for the project. I suggest to check for an equals instead of using StartsWith(). To stay consistent I propose to do this change for the start as well. So the code would change to

if (!canBegin)
{
    if (key == "Polyglot" || key == "PolyMaster" || key == "BEGIN")
    {
        canBegin = true;
    }
    continue;
}

if (key == "END")
{
    break;
}

If this is in the interest of those involved I would create a PR for it :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.