Ejemplo n.º 1
0
 /// <remarks/>
 public System.IAsyncResult BeginTranslate(TranslationMode translationMode, string textToTranslate, System.AsyncCallback callback, object asyncState)
 {
     return(this.BeginInvoke("Translate", new object[] {
         translationMode,
         textToTranslate
     }, callback, asyncState));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Translates an input address to the SD2SNES address space.
        /// </summary>
        /// <param name="address">
        /// An unsigned 32-bit integer representing the untranslated address.
        /// </param>
        /// <param name="mode">
        /// The translation mode.
        /// </param>
        /// <returns>
        /// An unsigned 32-bit integer representing the translated address.
        /// </returns>
        public static uint TranslateAddress(uint address, TranslationMode mode)
        {
            if (mode == TranslationMode.Read && MapAddressInRange(
                    address, 8257536U, 8388607U, 16056320U, out uint mappedAddress))
            {
                return(mappedAddress);
            }

            for (uint index = 0; index < 63U; ++index)
            {
                if (MapAddressInRange(address, (uint)((int)index * 65536 + 32768),
                                      (uint)((int)index * 65536 + ushort.MaxValue),
                                      index * 32768U, out mappedAddress) ||
                    MapAddressInRange(address, (uint)((int)index * 65536 + 8421376),
                                      (uint)((int)index * 65536 + 8454143),
                                      index * 32768U, out mappedAddress))
                {
                    return(mappedAddress);
                }
            }

            for (uint index = 0; index < 8U; ++index)
            {
                if (MapAddressInRange(address, (uint)(7340032 + (int)index * 65536),
                                      (uint)(7372799 + (int)index * 65536),
                                      (uint)(14680064 + (int)index * 32768), out mappedAddress))
                {
                    return(mappedAddress);
                }
            }

            return(address);
        }
Ejemplo n.º 3
0
        //  Pre-process the address to map into SD2SNES space
        public static uint TranslateAddress(uint address, TranslationMode mode)
        {
            uint translatedAddress;

            //  WRAM
            if (mode == TranslationMode.Read && MapAddressInRange(address, 0x7E0000u, 0x7FFFFFu, 0xF50000u, out translatedAddress))
            {
                return(translatedAddress);
            }

            //  ROM Segments
            for (uint i = 0u; i < 0x3Fu; i++)
            {
                if (MapAddressInRange(address, (i * 0x010000u) + 0x8000u, (i * 0x010000u) + 0xFFFFu, (i * 0x8000u), out translatedAddress))
                {
                    return(translatedAddress);
                }
                if (MapAddressInRange(address, (i * 0x010000u) + 0x808000u, (i * 0x010000u) + 0x80FFFFu, (i * 0x8000u), out translatedAddress))
                {
                    return(translatedAddress);
                }
            }

            //  SRAM Segments
            for (uint i = 0u; i < 8u; i++)
            {
                if (MapAddressInRange(address, 0x700000u + (i * 0x010000u), 0x707FFF + (i * 0x010000u), 0xE00000 + (i * 0x8000), out translatedAddress))
                {
                    return(translatedAddress);
                }
            }

            return(address);
        }
Ejemplo n.º 4
0
 public string Translate(TranslationMode translationMode, string textToTranslate)
 {
     object[] results = this.Invoke("Translate", new object[] {
         translationMode,
         textToTranslate
     });
     return((string)(results[0]));
 }
Ejemplo n.º 5
0
        private static string TranslateComments(string code, TranslationMode mode, string direction, bool useCorrector = true, int maxTranslationChars = 800)
        {
            MatchCollection collection = Program.CommentRegex.Matches(code);

            if (collection.Count <= 0)
            {
                return(null);
            }
            int           step = 0;
            int           translationReplacedCount = 0;
            StringBuilder result = new StringBuilder();
            int           index  = 0;

            foreach (Match match in collection)
            {
                Program.ConsoleProgressBar(++step, collection.Count);
                string toTranslate = match.Value.Trim('\\', '/', '-', '*', '_', ' ', '\t', '\n', '\r');
                if (toTranslate.StartsWith("\""))
                {
                    continue;
                }
                string translation = Program.ReversoTranslation(toTranslate, direction, useCorrector, maxTranslationChars);
                if (string.IsNullOrWhiteSpace(translation) || string.Equals(toTranslate.Trim('.', '_'), translation.Trim('.', '_'), StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                result.Append(code.Substring(index, match.Index - index));
                string output;
                switch (mode)
                {
                case TranslationMode.KeepOriginalTextAfterTranslation:
                    output = string.Format(CultureInfo.InvariantCulture, "{0} - {1}", translation, toTranslate);
                    break;

                case TranslationMode.KeepOriginalTextBeforeTranslation:
                    output = string.Format(CultureInfo.InvariantCulture, "{0} - {1}", toTranslate, translation);
                    break;

                case TranslationMode.TranslationOnly:
                default:
                    output = translation;
                    break;
                }
                result.Append(match.Value.Replace(toTranslate, output));
                index = match.Index + match.Length;
                ++translationReplacedCount;
            }
            if (translationReplacedCount <= 0)
            {
                return(null);
            }
            if (index < code.Length)
            {
                result.Append(code.Substring(index, code.Length - index));
            }
            return(result.ToString());
        }
Ejemplo n.º 6
0
        public async Task ChangeMode(long chatId, TranslationMode mode)
        {
            Group group = await _database.GetAsync(chatId);

            if (group.TranslationMode == mode)
            {
                return;
            }

            await _database.UpdateModeAsync(group, mode);
        }
Ejemplo n.º 7
0
    public void DestroyLinks()
    {
        //for (int i = mChainLength -1; i > 0; i--)
        //{
        //    Destroy(Instantiate(particle,
        //            mChainElementArray[i].transform.position,
        //            mChainElementArray[i].transform.rotation), 5);

        //    Destroy(mChainElementArray[i]);

        //}
        MoveStyle = TranslationMode.custom;
        StartCoroutine(ExplodeLinks());
    }
Ejemplo n.º 8
0
        private static bool IsPlaneTypeAllowed(
            TranslationMode translationMode, DetectedPlaneType planeType)
        {
            if (translationMode == TranslationMode.Any)
            {
                return(true);
            }

            if (translationMode == TranslationMode.Horizontal &&
                (planeType == DetectedPlaneType.HorizontalDownwardFacing ||
                 planeType == DetectedPlaneType.HorizontalUpwardFacing))
            {
                return(true);
            }

            if (translationMode == TranslationMode.Vertical &&
                planeType == DetectedPlaneType.Vertical)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
 /// <remarks/>
 public System.IAsyncResult BeginTranslate(TranslationMode translationMode, string textToTranslate, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("Translate", new object[] {
                 translationMode,
                 textToTranslate}, callback, asyncState);
 }
Ejemplo n.º 10
0
 public string Translate(TranslationMode translationMode, string textToTranslate) {
     object[] results = this.Invoke("Translate", new object[] {
                 translationMode,
                 textToTranslate});
     return ((string)(results[0]));
 }
Ejemplo n.º 11
0
 public void FixEnumValues(TranslationMode mode, object toFix)
 {
     FixEnumValues(this, mode, toFix);
 }
Ejemplo n.º 12
0
 public object TranslateEnum(Type enumType, TranslationMode mode, object id)
 {
     return(TranslateEnum(enumType, this, mode, id));
 }
Ejemplo n.º 13
0
 public T TranslateEnum <T>(TranslationMode mode, T id)
 {
     return((T)TranslateEnum(typeof(T), mode, id));
 }
        public ActionResult Edit(TranslationInput input)
        {
            //TODO: still need some improvements
            if (!ModelState.IsValid)
            {
                return(PartialView("EditTranslation", input));
            }
            input.Votes = 1;

            var updateMode = ITranslationMode.GetTranslationModeByID(input.TextId, input.LanguageCode);

            if (updateMode == null)//This mean it is the first Translation of this string
            {
                TranslationMode mode = new TranslationMode();
                mode.TextId       = input.TextId;
                mode.LanguageCode = input.LanguageCode;
                mode.Mode         = input.ModeOfTranslation;
                ITranslationMode.InsertTranslationMode(mode);

                updateMode = mode;

                if (input.ModeOfTranslation == 2)
                {
                    var griddata    = this.Gridformat();
                    var gridrowData = griddata.GridRows.Where(x => x.TextId == input.TextId).FirstOrDefault();
                    return(Json(MapToGridModel(gridrowData)));
                }
            }
            else
            {
                updateMode.Mode = input.ModeOfTranslation;
                ITranslationMode.UpdateTranslationMode(updateMode);

                if (updateMode.Mode == 2)
                {
                    var updateGriddata    = this.Gridformat();
                    var updateGridrowData = updateGriddata.GridRows.Where(x => x.TextId == input.TextId).FirstOrDefault();
                    return(Json(MapToGridModel(updateGridrowData)));
                }
            }

            var newtranslation = new Translation();

            if (updateMode.Mode == 0 || updateMode.Mode == 1)
            {
                var repetTranslated = ITranslation.GetAll().Where(x => x.TextId == input.TextId && x.LanguageCode == input.LanguageCode && x.Translated_Text == input.TranslationText).FirstOrDefault();
                if (repetTranslated != null)
                {
                    if (updateMode.Mode == 0)
                    {
                        var items = ITranslation.GetTranslationLogByCode(repetTranslated.TextId, repetTranslated.LanguageCode).ToList();
                        foreach (var item in items)
                        {
                            item.OfficialBoolean = false;
                        }
                        var maxVote = items.Max(s => s.Votes);
                        var setdata = items.Where(x => x.Votes == maxVote).FirstOrDefault();
                        setdata.OfficialBoolean = true;
                        setdata.Votes           = maxVote;

                        ITranslation.Update(setdata);
                    }
                    return(Json(repetTranslated));
                }

                //Find the las translation that has officialBoolean in true
                var translatedData = ITranslation.GetAll()
                                     .Where(x =>
                                            x.TextId == input.TextId &&
                                            x.LanguageCode == input.LanguageCode &&
                                            x.OfficialBoolean == true)
                                     .FirstOrDefault();

                if (translatedData != null)
                {
                    translatedData.OfficialBoolean = false;
                    translatedData.Votes           = translatedData.Votes > 0 ? 0 : translatedData.Votes;

                    //Update the last saved translation with the new values in order to put the new translation as the one to be shown in the grid.
                    // translateData is NOT the new input to be saved, is the last saved in a previous instance
                    ITranslation.Update(translatedData);
                }

                // the new translation to be saved in db
                var translatedText = new Translation();
                translatedText.Translated_Text = input.TranslationText;
                translatedText.LanguageCode    = input.LanguageCode;
                translatedText.TextId          = input.TextId;
                translatedText.Votes           = 0;
                translatedText.OfficialBoolean = true;

                ITranslation.Save(translatedText);

                newtranslation = ITranslation.GetAll().Where(x => x.Id == translatedText.Id).FirstOrDefault();

                this.VoteCount("Like", newtranslation.TextId, newtranslation.Id, newtranslation.LanguageCode);

                TranslationLog translation_log = new TranslationLog();
                translation_log.TextId          = translatedText.TextId;
                translation_log.System_Date     = DateTime.Now;
                translation_log.LanguageCode    = translatedText.LanguageCode;
                translation_log.Translated_Text = translatedText.Translated_Text;

                ITranslation_Log.Save(translation_log);
            }

            var data    = this.Gridformat();
            var rowData = data.GridRows.Where(x => x.TextId == input.TextId).FirstOrDefault();

            if (System.Web.HttpContext.Current.Request.Cookies["MissingTrans"] != null)
            {
                if (System.Web.HttpContext.Current.Request.Cookies["MissingTrans"].Value != "true")
                {
                    return(Json(MapToGridModel(rowData)));
                }
                else
                {
                    return(Json(data));
                }
            }
            else
            {
                return(Json(data));
            }
        }
Ejemplo n.º 15
0
 public Task <SortedDictionary <string, TranslationInfo> > GetTranslations(string language, TranslationMode mode = TranslationMode.Default)
 => _client.GetTranslations(_projectSlug, _resourceSlug, language, mode);
Ejemplo n.º 16
0
 public Task <string> GetRawTranslations(string language, TranslationMode mode = TranslationMode.Default)
 => _client.GetRawTranslations(_projectSlug, _resourceSlug, language, mode);
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            try
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Source Comment Translator v1.0 © 2020 by Johannes Fetz");
                Console.WriteLine("ReversoTranslation © 2020 Reverso-Softissimo. All rights reserved.");
                Console.WriteLine();
#if !DEBUG
                if (args.Length != 3)
                {
                    Console.WriteLine("Usage: [PATH] [REVERSO_DIRECTION] [MODE]");
                    Console.WriteLine("   - PATH : C style source file path");
                    Console.WriteLine(string.Format("   - REVERSO_DIRECTION : {0}", Program.GetAvailableDirections()));
                    Console.WriteLine("   - MODE : 0 to keep orginal text before translation");
                    Console.WriteLine("   - MODE : 1 translation only");
                    Console.WriteLine("   - MODE : 2 to keep orginal text after translation");
                    Console.WriteLine();
                    Console.WriteLine("Example: MY_HEADER.H jpn-eng 2");
                    return;
                }
#endif
                string path = args[0];
                if (!File.Exists(path))
                {
                    Program.Error(string.Format("{0} not found.", path));
                }
                string outputPath = Path.Combine(Path.GetDirectoryName(path), String.Concat(Path.GetFileNameWithoutExtension(path), ".TRANSLATED", Path.GetExtension(path)));

                string direction = args[1].ToLowerInvariant();
                if (!Program.AvailableReversoDirections.Contains(direction))
                {
                    Program.Error(string.Format("Available Reverso direction : {0}", Program.GetAvailableDirections()));
                }

                int modeInt;
                if (!int.TryParse(args[2], out modeInt))
                {
                    Program.Error("Invalid mode.");
                }
                TranslationMode mode = (TranslationMode)modeInt;

                byte[]   raw                 = File.ReadAllBytes(path);
                Encoding sourceEncoding      = direction.StartsWith("jpn") ? Encoding.GetEncoding(932) : Encoding.UTF8;
                Encoding destinationEncoding = direction.EndsWith("jpn") ? Encoding.GetEncoding(932) : Encoding.UTF8;
                string   contents            = sourceEncoding.GetString(raw);

                direction += "-5"; // We append the "-5" direction suffix for reverso;
                string res = Program.TranslateComments(contents, mode, direction);
                Console.WriteLine();
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Green;
                if (res != null)
                {
                    File.WriteAllText(outputPath, res, destinationEncoding);
                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} generated.", Path.GetFileName(outputPath)));
                }
                else
                {
                    Console.WriteLine("Nothing to translate.");
                }
            }
            catch (Exception ex)
            {
                Program.Error(ex.Message);
            }
            finally
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Calculates the best position to place an object in AR based on screen position.
        /// Could be used for tapping a location on the screen, dragging an object, or using a fixed
        /// cursor in the center of the screen for placing and moving objects.
        ///
        /// Objects are placed along the x/z of the grounding plane. When placed on an AR plane
        /// below the grounding plane, the object will drop straight down onto it in world space.
        /// This prevents the object from being pushed deeper into the scene when moving from a
        /// higher plane to a lower plane. When moving from a lower plane to a higher plane, this
        /// function returns a new groundingPlane to replace the old one.
        /// </summary>
        /// <returns>The best placement position.</returns>
        /// <param name="currentAnchorPosition">Position of the parent anchor, i.e., where the
        /// object is before translation starts.</param>
        /// <param name="screenPos">Location on the screen in pixels to place the object at.</param>
        /// <param name="groundingPlaneHeight">The starting height of the plane that the object is
        /// being placed along.</param>
        /// <param name="hoverOffset">How much should the object hover above the groundingPlane
        /// before it has been placed.</param>
        /// <param name="maxTranslationDistance">The maximum distance that the object can be
        /// translated.</param>
        /// <param name="translationMode">The translation mode, indicating the plane types allowed.
        /// </param>
        public static Placement GetBestPlacementPosition(
            Vector3 currentAnchorPosition,
            Vector2 screenPos,
            float groundingPlaneHeight,
            float hoverOffset,
            float maxTranslationDistance,
            TranslationMode translationMode)
        {
            Placement result = new Placement();

            result.UpdatedGroundingPlaneHeight = groundingPlaneHeight;

            // Get the angle between the camera and the object's down direction.
            float angle = Vector3.Angle(Camera.main.transform.forward, Vector3.down);

            angle = 90.0f - angle;

            float touchOffsetRatio  = Mathf.Clamp01(angle / 90.0f);
            float screenTouchOffset = touchOffsetRatio * k_MaxScreenTouchOffset;

            screenPos.y += GestureTouchesUtility.InchesToPixels(screenTouchOffset);

            float hoverRatio = Mathf.Clamp01(angle / 45.0f);

            hoverOffset *= hoverRatio;

            float distance           = (Camera.main.transform.position - currentAnchorPosition).magnitude;
            float distanceHoverRatio = Mathf.Clamp01(distance / k_HoverDistanceThreshold);

            hoverOffset *= distanceHoverRatio;

            // The best estimate of the point in the plane where the object will be placed:
            Vector3 groundingPoint;

            // Get the ray to cast into the scene from the perspective of the camera.
            TrackableHit hit;

            if (Frame.Raycast(
                    screenPos.x, screenPos.y, TrackableHitFlags.PlaneWithinBounds, out hit))
            {
                if (hit.Trackable is DetectedPlane)
                {
                    DetectedPlane plane = hit.Trackable as DetectedPlane;
                    if (IsPlaneTypeAllowed(translationMode, plane.PlaneType))
                    {
                        // Avoid detecting the back of existing planes.
                        if ((hit.Trackable is DetectedPlane) &&
                            Vector3.Dot(Camera.main.transform.position - hit.Pose.position,
                                        hit.Pose.rotation * Vector3.up) < 0)
                        {
                            Debug.Log("Hit at back of the current DetectedPlane");
                            return(result);
                        }

                        // Don't allow hovering for vertical or horizontal downward facing planes.
                        if (plane.PlaneType == DetectedPlaneType.Vertical ||
                            plane.PlaneType == DetectedPlaneType.HorizontalDownwardFacing)
                        {
                            // Limit the translation to maxTranslationDistance.
                            groundingPoint = LimitTranslation(
                                hit.Pose.position, currentAnchorPosition, maxTranslationDistance);
                            groundingPoint.y                   = groundingPlaneHeight;
                            result.PlacementPlane              = hit;
                            result.PlacementPosition           = groundingPoint;
                            result.HoveringPosition            = groundingPoint;
                            result.UpdatedGroundingPlaneHeight = groundingPoint.y;
                            //result.PlacementRotation = hit.Pose.rotation;
                            return(result);
                        }

                        // Allow hovering for horizontal upward facing planes.
                        if (plane.PlaneType == DetectedPlaneType.HorizontalUpwardFacing)
                        {
                            // Return early if the camera is pointing upwards.
                            if (angle < 0f)
                            {
                                return(result);
                            }

                            // Limit the translation to maxTranslationDistance.
                            groundingPoint = LimitTranslation(
                                hit.Pose.position, currentAnchorPosition, maxTranslationDistance);
                            groundingPoint.y = groundingPlaneHeight; //changed
                            // Find the hovering position by casting from the camera onto the
                            // grounding plane and offsetting the result by the hover offset.
                            result.HoveringPosition = groundingPoint + (Vector3.up * hoverOffset);

                            // If the AR Plane is above the grounding plane, then the hit plane's
                            // position is used to replace the current groundingPlane. Otherwise,
                            // the hit is ignored because hits are only detected on lower planes by
                            // casting straight downwards in world space.
                            if (groundingPoint.y > groundingPlaneHeight)
                            {
                                result.PlacementPlane              = hit;
                                result.PlacementPosition           = groundingPoint;
                                result.UpdatedGroundingPlaneHeight = hit.Pose.position.y;
                                //result.PlacementRotation = hit.Pose.rotation;
                                return(result);
                            }
                        }
                        else
                        {
                            // Not supported plane type.
                            return(result);
                        }
                    }
                    else
                    {
                        // Plane type not allowed.
                        return(result);
                    }
                }
                else
                {
                    // Hit is not a plane.
                    return(result);
                }
            }

            // Return early if the camera is pointing upwards.
            if (angle < 0f)
            {
                return(result);
            }

            // If the grounding point is lower than the current gorunding plane height, or if the
            // raycast did not return a hit, then we extend the grounding plane to infinity, and do
            // a new raycast into the scene from the perspective of the camera.
            Ray   cameraRay      = Camera.main.ScreenPointToRay(screenPos);
            Plane groundingPlane =
                new Plane(Vector3.up, new Vector3(0.0f, groundingPlaneHeight, 0.0f));

            // Find the hovering position by casting from the camera onto the grounding plane
            // and offsetting the result by the hover offset.
            float enter;

            if (groundingPlane.Raycast(cameraRay, out enter))
            {
                groundingPoint = LimitTranslation(
                    cameraRay.GetPoint(enter), currentAnchorPosition, maxTranslationDistance);
                groundingPoint.y        = groundingPlaneHeight; //changed
                result.HoveringPosition = groundingPoint + (Vector3.up * hoverOffset);
            }
            else
            {
                // If we can't successfully cast onto the groundingPlane, just return early.
                return(result);
            }

            // Cast straight down onto AR planes that are lower than the current grounding plane.
            if (Frame.Raycast(
                    groundingPoint + (Vector3.up * k_DownRayOffset), Vector3.down,
                    out hit, Mathf.Infinity, TrackableHitFlags.PlaneWithinBounds))
            {
                result.PlacementPosition = hit.Pose.position;
                result.PlacementPlane    = hit;
                //result.PlacementRotation = hit.Pose.rotation;
                //result.UpdatedGroundingPlaneHeight = groundingPlaneHeight;//changed
                return(result);
            }

            return(result);
        }
Ejemplo n.º 19
0
 public async Task UpdateModeAsync(Group groupIn, TranslationMode mode)
 {
     groupIn.TranslationMode = mode;
     _databaseContext.Update(groupIn);
     await _databaseContext.SaveChangesAsync();
 }