Exemple #1
0
        // this will return the langTo version of the EN phrase
        public string tran(string phraseIn, string lang)
        {
            string phraseEx;

            // ensure we have a valid lang, else assume en
            if (lang != "fr" && lang != "es" && lang != "pt")
            {
                return(phraseIn);
            }
            else
            {
                // this instantiates the translate object
                //Translate translate = new Translate();

                // grab the translated phrase
                JSON = v8server.translate(phraseIn, lang);
                List <LangParameters> langParameters = serializer.Deserialize <List <LangParameters> >(JSON);
                phraseEx = langParameters[0].phrase;
                // if there is no translated value...
                if (phraseEx == null || phraseEx.Length == 0)
                {
                    phraseEx = Translate.translatePhrase(phraseIn, lang);          // get one from MS Translator
                    JSON     = v8server.translateUpdate(phraseIn, lang, phraseEx); // update the translation table
                }
                return(phraseEx);
            }
        }
Exemple #2
0
        public string translate(string text, string lang) // translate a block of code (HTML or Script) from [[english text]] to "lang" (note supports only left to right langs, not RTL like Arabic))
        {
            // only use this service if the app requires translation - if not ensure there are not tags from routines that might use them
            if (!translateApp)
            {
                return(text.Replace("[[", "").Replace("]]", ""));
            }

            // this instantiates the translate object (no longer functional when moved to azure)
            // Translate translate = new Translate();

            // first ensure there are same number of matching tags
            int l = 0, r = 0;

            for (int i = 0; i <= text.Length - 2; i++)
            {
                if (text.Substring(i, 2) == "[[")
                {
                    l++;
                }
                if (text.Substring(i, 2) == "]]")
                {
                    r++;
                }
            }
            if (l != r)
            {
                Response.Redirect("Errors.aspx?errorId=460&errorParm=" + appId, true);
            }

            // since all prompts are in EN, unless we are translating to fr/es or pb then simply remove the starting and ending "tags"
            if (lang != "fr" && lang != "es" && lang != "pt")
            {
                text = text.Replace("[[", "");
                text = text.Replace("]]", "");
            }

            // otherwise, get all phraseIns between the tags and replace with the lang equivalent
            else
            {
                // web service used for profiles/profileParameters/autoEnroll/translation, etc
                com.v8server         v8server   = new com.v8server();
                JavaScriptSerializer serializer = new JavaScriptSerializer();

                int    str = 0, end = text.Length - 1, fr = 0, to = 0;
                string JSON, phraseIn = "", phraseEx = "", left = "", right = "";


                while (str < end)
                {
                    fr = text.IndexOf("[[", str);
                    if (fr == -1)
                    {
                        end = 0;
                    }
                    else
                    {
                        to = text.IndexOf("]]", fr + 2);
                        if (to == -1)
                        {
                            end = 0;
                        }
                        else
                        {
                            phraseIn = text.Substring(fr + 2, to - fr - 2);

                            str   = to + 2;
                            left  = text.Substring(0, fr);
                            right = text.Substring(to + 2);

                            // grab the translated phrase
                            JSON = v8server.translate(phraseIn, lang);
                            List <LangParameters> langParameters = serializer.Deserialize <List <LangParameters> >(JSON);
                            phraseEx = langParameters[0].phrase;

                            // if there is no translated value (note: orginally got value from Bing translator before that moved to Azure
                            // too complex now so if not on DB then return EN
                            if (phraseEx == null || phraseEx.Length == 0)
                            {
                                //phraseEx = translate.translatePhrase(phraseIn, lang);           // get one from MS Translator
                                //JSON = v8server.translateUpdate(phraseIn, lang, phraseEx);      // update the translation table
                                phraseEx = phraseIn;
                            }

                            // lock in FR quotes « »
                            phraseEx = phraseEx.Replace("« ", "«&nbsp;");
                            phraseEx = phraseEx.Replace(" »", "&nbsp;»");

                            text = left + phraseEx + right;
                        }
                    }
                }
            }
            return(text);
        }