コード例 #1
0
        public TryCatchTranslation(TryExpression tryCatchFinally, ITranslationContext context)
        {
            Type = tryCatchFinally.Type;
            _isNonVoidTryCatch = Type != typeof(void);

            _bodyTranslation = GetReturnableBlockTranslation(tryCatchFinally.Body, context);

            _catchBlockTranslations = GetCatchBlockTranslations(
                tryCatchFinally.Handlers,
                out var estimatedCatchBlocksSize,
                context);

            _hasFault = tryCatchFinally.Fault != null;

            if (_hasFault)
            {
                _faultTranslation = GetReturnableBlockTranslation(tryCatchFinally.Fault, context);
            }

            _hasFinally = tryCatchFinally.Finally != null;

            if (_hasFinally)
            {
                _finallyTranslation = GetReturnableBlockTranslation(tryCatchFinally.Finally, context);
            }

            EstimatedSize = GetEstimatedSize(estimatedCatchBlocksSize);
        }
コード例 #2
0
        private static IList <ITranslatable> GetCatchBlockTranslations(
            IList <CatchBlock> catchBlocks,
            out int estimatedCatchBlocksSize,
            ITranslationContext context)
        {
            if (catchBlocks.Count == 0)
            {
                estimatedCatchBlocksSize = 0;
                return(Enumerable <ITranslatable> .EmptyArray);
            }

            var catchBlockTranslations = new ITranslatable[catchBlocks.Count];

            estimatedCatchBlocksSize = 0;

            for (int i = 0, l = catchBlocks.Count; ;)
            {
                var catchBlockTranslation = new CatchBlockTranslation(catchBlocks[i], context);

                estimatedCatchBlocksSize += catchBlockTranslation.EstimatedSize;
                catchBlockTranslations[i] = catchBlockTranslation;

                if (++i == l)
                {
                    break;
                }
            }

            return(catchBlockTranslations);
        }
コード例 #3
0
ファイル: TranslationUtil.cs プロジェクト: ugt-software/LMIS
        public static void ApplyTranslation(ITranslatable translatable)
        {
            if (!EnableTranslation)
            {
                return;
            }

            if (String.IsNullOrEmpty(translatable.Text))
            {
                return;
            }

            var defaultText = GetClearText(translatable);

            if (String.IsNullOrEmpty(translatable.TrnKey))
            {
                translatable.TrnKey = CryptographyUtil.ComputeMD5(defaultText);
            }

            translatable.Text = GetTranslatedText(translatable.TrnKey, defaultText);

            var defTranslatable = translatable as DefaultTranslatable;

            if (defTranslatable != null)
            {
                defTranslatable.Text = GetClearText(translatable);

                if (TranslationMode)
                {
                    defTranslatable.Link = GetTranslationLink(translatable);
                }
            }
        }
コード例 #4
0
        public LabelTranslation(LabelExpression label, ITranslationContext context)
        {
            Type             = label.Type;
            _labelName       = GetLabelNamePart(label, context);
            _labelIsNamed    = _labelName != null;
            _labelHasNoValue = label.DefaultValue == null;

            if (_labelIsNamed)
            {
                // ReSharper disable once PossibleNullReferenceException
                TranslationSize = _labelName.Length + 1 + Environment.NewLine.Length;
            }
            else if (_labelHasNoValue)
            {
                IsEmpty = true;
                return;
            }

            IsTerminated = true;

            if (_labelHasNoValue)
            {
                return;
            }

            _labelValueTranslation = context.GetCodeBlockTranslationFor(label.DefaultValue);
            TranslationSize       += _labelValueTranslation.TranslationSize;
            FormattingSize         = _labelValueTranslation.FormattingSize;
        }
コード例 #5
0
        /// <summary>
        /// Apply translation to a container
        /// </summary>
        /// <param name="container"></param>
        /// <param name="tranlations"></param>
        private void ApplyTranslation(Container container, List <Translation> tranlations = null)
        {
            if (tranlations != null)
            {
                foreach (Control c in container.Controls)
                {
                    if (c is ITranslatable)
                    {
                        ITranslatable tControl = (ITranslatable)c;

                        if (!string.IsNullOrEmpty(tControl.TranslateKey))
                        {
                            if (c is ITextRenderable)
                            {
                                ITextRenderable textControl = (ITextRenderable)c;
                                textControl.Text = (from t in tranlations where t.Key == tControl.TranslateKey select t).Single().Value;
                            }
                        }
                    }
                }
            }
            else
            {
                throw new GuiEngineException(typeof(GuiShot).Name, "Obligé d'avoir un liste de traduction !!!!");//todo add in ressources
            }
        }
コード例 #6
0
ファイル: TranslationUtil.cs プロジェクト: ugt-software/LMIS
        public static String GetTranslationLink(ITranslatable translatable)
        {
            var moduleName   = PermissionUtil.ModuleName;
            var languagePair = Thread.CurrentThread.CurrentCulture.Name;

            return(GetTranslationLink(moduleName, translatable.TrnKey, languagePair));
        }
        /// <summary>
        /// Imports a given translation on a given translatable domain object.
        /// </summary>
        /// <param name="domainObject">Translatable domain object on which to import the translation.</param>
        /// <param name="translationInfo">Translation informations for the translation to import.</param>
        /// <param name="translationValue">The translation value for the translatable domain object.</param>
        /// <param name="logicExecutor">Implementation of the logic executor which can execute basic logic.</param>
        /// <returns>The imported translation.</returns>
        protected virtual ITranslation ImportTranslation(ITranslatable domainObject, ITranslationInfo translationInfo, string translationValue, ILogicExecutor logicExecutor)
        {
            if (domainObject == null)
            {
                throw new ArgumentNullException("domainObject");
            }
            if (translationInfo == null)
            {
                throw new ArgumentNullException("translationInfo");
            }
            if (string.IsNullOrEmpty(translationValue))
            {
                throw new ArgumentNullException("translationValue");
            }
            if (logicExecutor == null)
            {
                throw new ArgumentNullException("logicExecutor");
            }
            var domainObjectIdentifier    = domainObject.Identifier.HasValue ? domainObject.Identifier.Value : default(Guid);
            var translationInfoIdentifier = translationInfo.Identifier.HasValue ? translationInfo.Identifier.Value : default(Guid);
            var translation = domainObject.Translations.SingleOrDefault(m => m.TranslationOfIdentifier == domainObjectIdentifier && m.TranslationInfo.Identifier.HasValue && m.TranslationInfo.Identifier.Value == translationInfoIdentifier);

            if (translation == null)
            {
                var insertedTranslation = new Translation(domainObjectIdentifier, translationInfo, translationValue);
                insertedTranslation.Identifier = logicExecutor.TranslationAdd(insertedTranslation);
                domainObject.TranslationAdd(insertedTranslation);
                return(insertedTranslation);
            }
            translation.Value      = translationValue;
            translation.Identifier = logicExecutor.TranslationModify(translation);
            return(translation);
        }
コード例 #8
0
        protected void ScriptChanged(object sender, EventArgs e)
        {
            try {
                if (!IsDirty)
                {
                    IsDirty = true;
                }

                ITranslatable nlProvider = sender as ITranslatable;
                if (nlProvider == null)
                {
                    throw new InvalidOperationException("Sender does not implement ITranslatable.");
                }

                string nl = UpdateNaturalLanguageView(nlProvider);

                if (nl != previousNaturalLanguageValue)
                {
                    //ActivityLog.Write(new Activity("ScriptDump","NLOutput",nl));
                    Log.WriteMessage("script output: " + nl.Replace(Environment.NewLine, String.Empty));                    // remove new line characters
                    previousNaturalLanguageValue = nl;
                }
            }
            catch (Exception x) {
                MessageBox.Show("Something went wrong when responding to the script changing.\n\n" + x);
            }
        }
コード例 #9
0
        private void LoadTranslatable(Type translatable)
        {
            string          path         = null;
            TranslationList translations = null;
            Dictionary <Type, ITranslatable> dictionary = null;
            ITranslatable translater = (ITranslatable)Activator.CreateInstance(translatable);

            path         = translater.TranslationDirectory;
            translations = translater.Translations;
            dictionary   = translater.TranslationDictionary;
            if (dictionary != null)
            {
                dictionary.Add(translatable, translater);
            }

            UniversalData UniData;

            if (_SavedTranslations.ContainsKey(translater))
            {
                UniData = _SavedTranslations[translater];
            }
            else
            {
                UniData = new UniversalData(PointBlankServer.TranslationsPath + "/" + (string.IsNullOrEmpty(path) ? "" : path + "/") + translatable.Name);
            }
            JsonData JSON = UniData.GetData(EDataType.JSON) as JsonData;

            if (!_SavedTranslations.ContainsKey(translater))
            {
                _SavedTranslations.Add(translater, UniData);
            }
            if (UniData.CreatedNew)
            {
                foreach (KeyValuePair <string, string> kvp in translations)
                {
                    if (JSON.CheckKey(kvp.Key))
                    {
                        JSON.Document[kvp.Key] = kvp.Value;
                    }
                    else
                    {
                        JSON.Document.Add(kvp.Key, kvp.Value);
                    }
                }
            }
            else
            {
                foreach (JProperty property in JSON.Document.Properties())
                {
                    if (translations[property.Name] == null)
                    {
                        continue;
                    }

                    translations[property.Name] = (string)property.Value;
                }
            }
            UniData.Save();
        }
コード例 #10
0
        /**
         * <summary>Gets the text of an ITranslatable instance, based on the game's current language.</summary>
         * <param name = "translatable">The ITranslatable instance.</param>
         * <param name = "index">The index of the ITranslatable's array of translatable text</param>
         * <returns>The translatable text.</returns>
         */
        public string GetTranslatableText(ITranslatable translatable, int index = 0)
        {
            int    language     = Options.GetLanguage();
            string originalText = translatable.GetTranslatableString(index);
            int    lineID       = translatable.GetTranslationID(index);

            return(GetTranslation(originalText, lineID, language));
        }
コード例 #11
0
 public ModifiedTranslation(
     ITranslatable baseTranslatable,
     ExpressionType nodeType,
     Type type)
 {
     _baseTranslatable = baseTranslatable;
     NodeType          = nodeType;
     Type = type;
 }
コード例 #12
0
 public MetaReplyMessage(
     ITranslatable metaText                  = null,
     MessageType messageType                 = MessageType.Text,
     InputOnlineFile messageFile             = null,
     MetaReplyKeyboardMarkup messageKeyboard = null,
     ParseMode parsing = ParseMode.Markdown) :
     base(metaText, messageType, messageFile, messageKeyboard, parsing)
 {
     MetaKeyboard = MetaKeyboard ?? new MetaReplyKeyboardMarkup();
 }
コード例 #13
0
 public TranslationWriter(ITranslationSettings settings, ITranslatable translatable)
     : this(
         settings.Formatter,
         settings.Indent,
         translatable.TranslationSize +
         translatable.FormattingSize +
         translatable.GetIndentSize())
 {
     translatable.WriteTo(this);
 }
コード例 #14
0
        /// <summary>
        /// Translate an <see cref="ITranslatable"/> item, with optional string replacement. The <code>defaultText</code>
        /// can be used to specify an alternate translation. Passing <code>null</code> will result in a warning message
        /// about a missing translation ID.
        /// </summary>
        /// <param name="item">
        /// A <see cref="ITranslatable"/> to set the text for
        /// </param>
        /// <param name="defaultText">
        /// The default string to display if no translation could be found.
        /// </param>
        /// <param name="replacements">
        /// A collection of <see cref="System.Object"/>s that will be used to fill place-holders
        /// </param>
        public static void Translate(ITranslatable item, string defaultText, params object[] replacements)
        {
            if (item.Text == "")
            {
                //it doesn't need translating - either there is no text from the developer or it's a hyphen for a divider
                return;
            }

            item.Text = GetTranslation(item.Name, defaultText, replacements);
        }
コード例 #15
0
        /// <summary>
        /// Create translation structure at scope of tranlatable object.
        /// </summary>
        /// <param name="translatableObject">Translateable object</param>
        /// <param name="culture">Culture which is used to store translation</param>
        public static void SaveTranslation(this ITranslatable translatableObject, string culture)
        {
            #region validation

            if (translatableObject == null)
            {
                throw new ArgumentNullException(nameof(translatableObject));
            }

            if (string.IsNullOrEmpty(culture))
            {
                throw new ArgumentNullException(nameof(culture));
            }

            #endregion

            // create translation structure if not exists
            if (translatableObject.Translations == null)
            {
                translatableObject.Translations = new List <Translation>();
            }

            // check if translation for specified culture already exists
            Translation translation = translatableObject.GetTranslation(culture);
            if (translation == null)
            {
                // create translation for specified culture
                translation = new Translation()
                {
                    Culture = culture
                };
                translatableObject.Translations.Add(translation);
            }

            List <TranslationText> translationTexts = new List <TranslationText>();

            // get all properties with 'translatable' annotation which are of type string
            Type translationType = translatableObject.GetType();
            foreach (PropertyInfo translationProperty in translationType.GetTranslatableProperties())
            {
                translationTexts.Add(new TranslationText()
                {
                    Name = translationProperty.Name,
                    Text = (string)translationProperty.GetValue(translatableObject)
                });
            }

            translation.Texts = translationTexts;

            if (!string.IsNullOrEmpty(Instance.DefaultCulture))
            {
                // reset culture dependend properties to default language
                translatableObject.Translate(Instance.DefaultCulture);
            }
        }
コード例 #16
0
 public TranslateTransition(ITranslatable obj, int fromX, int fromY, int toX, int toY, bool queue = true, float speed = 0.05f, Action onBegin = null, Action onEnd = null) :
     base(obj, queue, speed, onBegin, onEnd)
 {
     _target = obj;
     _fromX  = fromX;
     _fromY  = fromY;
     _toX    = toX;
     _toY    = toY;
     _dX     = (float)(_toX - _fromX) * speed;
     _dY     = (float)(_toY - _fromY) * speed;
 }
コード例 #17
0
        protected string UpdateNaturalLanguageView(ITranslatable translatable)
        {
            if (translatable == null)
            {
                return(null);
            }
            string nl = translatable.GetNaturalLanguage();

            NaturalLanguage = nl;
            return(nl);
        }
コード例 #18
0
            public BlockAssignmentStatementTranslation(BinaryExpression assignment, ITranslationContext context)
                : base(assignment, context)
            {
                if (UseFullTypeName(assignment))
                {
                    _typeNameTranslation = context.GetTranslationFor(assignment.Left.Type);
                    EstimatedSize       += _typeNameTranslation.EstimatedSize + 2;
                    return;
                }

                EstimatedSize += _var.Length;
            }
コード例 #19
0
        public void Init <TTranslation>(Func <TTranslation, string> titleId, Func <ConversionProfile, IProfileSetting> setting, PrismNavigationValueObject navigationObject) where TTranslation : ITranslatable, new()
        {
            _setting          = setting;
            _navigationObject = navigationObject;

            _translationUpdater.RegisterAndSetTranslation(tf =>
            {
                var translation = tf.UpdateOrCreateTranslation((TTranslation)_translation);
                _translation    = translation;
                Title           = titleId(translation);
            });
        }
コード例 #20
0
        private void SetStringProperty(ITranslatable o, PropertyInfo property, ITranslationSource translationSource)
        {
            var value   = (string)property.GetValue(o, null);
            var context = ContextAttribute.GetValue(property);

            var translated = translationSource.GetTranslation(value, context);

            if (!string.IsNullOrEmpty(translated))
            {
                property.SetValue(o, translated, null);
            }
        }
コード例 #21
0
 public MultiLineBinaryConditionTranslation(
     BinaryExpression binaryCondition,
     ITranslatable conditionTranslatable,
     ITranslationContext context)
 {
     _context = context;
     NodeType = binaryCondition.NodeType;
     _binaryConditionLeftTranslation  = For(binaryCondition.Left, context);
     _binaryConditionOperator         = BinaryTranslation.GetOperator(binaryCondition);
     _binaryConditionRightTranslation = For(binaryCondition.Right, context);
     TranslationSize = conditionTranslatable.TranslationSize;
     FormattingSize  = conditionTranslatable.FormattingSize;
 }
コード例 #22
0
        /// <summary>
        /// Get fallback translation structure for specified culture.
        /// </summary>
        /// <param name="translatableObject">Object which should be translated</param>
        /// <param name="culture">Culture for translation</param>
        /// <returns>Fallback translation for specific culture or NULL</returns>
        private static Translation GetTranslationFallBack(this ITranslatable translatableObject, string culture)
        {
            #region validation

            if (string.IsNullOrEmpty(culture))
            {
                throw new ArgumentNullException(nameof(culture));
            }

            #endregion

            return(translatableObject.Translations.FirstOrDefault(o => o.Culture.StartsWith(culture, StringComparison.CurrentCultureIgnoreCase)));;
        }
コード例 #23
0
        public PropertyDefinitionTranslation(
            PropertyInfo property,
            MethodInfo[] accessors,
            ITranslationSettings settings)
        {
            _accessibility = GetAccessibility(property);
            _modifiers     = GetModifiers(accessors[0]);

            _propertyTypeTranslation =
                new TypeNameTranslation(property.PropertyType, settings);

            _propertyName = property.Name;

            var translationSize =
                _accessibility.Length +
                _modifiers.Length +
                _propertyTypeTranslation.TranslationSize +
                _propertyName.Length;

            var keywordFormattingSize = settings.GetKeywordFormattingSize();

            var formattingSize =
                keywordFormattingSize + // <- For modifiers
                _propertyTypeTranslation.FormattingSize;

            if (property.DeclaringType != null)
            {
                _declaringTypeNameTranslation =
                    new TypeNameTranslation(property.DeclaringType, settings);

                translationSize += _declaringTypeNameTranslation.TranslationSize + ".".Length;
                formattingSize  += _declaringTypeNameTranslation.FormattingSize;
            }

            _accessorTranslations = new ITranslatable[accessors.Length];

            for (var i = 0; i < accessors.Length; ++i)
            {
                var accessorTranslation =
                    new PropertyAccessorDefinitionTranslation(this, accessors[i], settings);

                translationSize += accessorTranslation.TranslationSize;
                formattingSize  += accessorTranslation.FormattingSize;

                _accessorTranslations[i] = accessorTranslation;
            }

            TranslationSize = translationSize;
            FormattingSize  = formattingSize;
        }
コード例 #24
0
            private ITranslatable[] GetRequiredExplicitGenericArguments(
                ITranslationContext context,
                out int translationsSize)
            {
                if (!_method.IsGenericMethod)
                {
                    translationsSize = 0;
                    return(Enumerable <ITranslatable> .EmptyArray);
                }

                var methodGenericDefinition = _method.GetGenericMethodDefinition();
                var genericParameterTypes   = methodGenericDefinition.GetGenericArguments().ToList();

                if (context.Settings.UseImplicitGenericParameters)
                {
                    RemoveSuppliedGenericTypeParameters(
                        methodGenericDefinition.GetParameters().Project(p => p.ParameterType),
                        genericParameterTypes);
                }

                if (!genericParameterTypes.Any())
                {
                    translationsSize = 0;
                    return(Enumerable <ITranslatable> .EmptyArray);
                }

                var argumentTranslationsSize = 0;

                var arguments = _method
                                .GetGenericArguments()
                                .Project(argumentType =>
                {
                    if (argumentType.FullName == null)
                    {
                        return(null);
                    }

                    ITranslatable argumentTypeTranslation = context.GetTranslationFor(argumentType);

                    argumentTranslationsSize += argumentTypeTranslation.TranslationSize + 2;

                    return(argumentTypeTranslation);
                })
                                .Filter(argument => argument != null)
                                .ToArray();

                translationsSize = argumentTranslationsSize;

                return((translationsSize != 0) ? arguments : Enumerable <ITranslatable> .EmptyArray);
            }
コード例 #25
0
        public void Init <TTranslation>(Func <TTranslation, string> titleId, Func <ConversionProfile, IProfileSetting> setting, PrismNavigationValueObject navigationObject, Func <ConversionProfile, bool> hasNotSupportedFeatures = null) where TTranslation : ITranslatable, new()
        {
            _setting = setting;

            _hasNotSupportedFeatures = hasNotSupportedFeatures ?? (p => false);
            _navigationObject        = navigationObject;

            _translationUpdater.RegisterAndSetTranslation(tf =>
            {
                var translation = tf.UpdateOrCreateTranslation((TTranslation)_translation);
                _translation    = translation;
                Title           = titleId(translation);
            });
        }
コード例 #26
0
            public BlockAssignmentStatementTranslation(BinaryExpression assignment, ITranslationContext context)
                : base(assignment, context)
            {
                if (UseFullTypeName(assignment, context))
                {
                    _typeNameTranslation = context.GetTranslationFor(assignment.Left.Type);
                    TranslationSize     += _typeNameTranslation.TranslationSize + 2;
                    FormattingSize      += _typeNameTranslation.FormattingSize;
                    return;
                }

                TranslationSize += _var.Length;
                FormattingSize  += context.GetKeywordFormattingSize();
            }
コード例 #27
0
        public TypeDefinitionTranslation(Type type, ITranslationSettings settings)
        {
            _accessibility        = GetAccessibility(type);
            _modifiers            = GetModifiers(type);
            _typeNameTranslatable = new TypeNameTranslation(type, settings);

            TranslationSize =
                _accessibility.Length +
                _modifiers.Length +
                _typeNameTranslatable.TranslationSize;

            FormattingSize =
                settings.GetKeywordFormattingSize() + // <- For modifiers
                _typeNameTranslatable.FormattingSize;
        }
        public ConstructorDefinitionTranslation(
            ConstructorInfo ctor,
            ITranslationSettings settings)
        {
            _accessibility         = GetAccessibility(ctor);
            _typeNameTranslation   = new TypeNameTranslation(ctor.DeclaringType, settings);
            _parametersTranslation = new ParameterSetDefinitionTranslation(ctor, settings);

            TranslationSize =
                _typeNameTranslation.TranslationSize +
                _parametersTranslation.TranslationSize;

            FormattingSize =
                settings.GetKeywordFormattingSize() + // <- for modifiers
                _typeNameTranslation.FormattingSize +
                _parametersTranslation.FormattingSize;
        }
コード例 #29
0
            public CatchBlockTranslation(CatchBlock catchBlock, ITranslationContext context)
            {
                _catchBodyTranslation = GetBlockTranslation(catchBlock.Body, context);
                _exceptionClause      = GetExceptionClauseOrNullFor(catchBlock, context);

                if ((_catchBodyTranslation.NodeType != ExpressionType.Throw) && catchBlock.Body.IsReturnable())
                {
                    _catchBodyTranslation.WithReturnKeyword();
                }

                EstimatedSize = _catchBodyTranslation.EstimatedSize;

                if (_exceptionClause != null)
                {
                    EstimatedSize += _exceptionClause.EstimatedSize;
                }
            }
コード例 #30
0
        public ResxFile(ITranslatable source)
        {
            _deleteOnDispose = true;
            Path             = System.IO.Path.GetTempFileName();

            using (var writer = new ResXResourceWriter(Path))
            {
                foreach (var unit in source.GetTranslationUnits())
                {
                    HasStrings = true;
                    writer.AddResource(new ResXDataNode(unit.Id, unit.Source)
                    {
                        Comment = unit.Note
                    });
                }
            }
        }
コード例 #31
0
ファイル: Translator.cs プロジェクト: t1b1c/lwas
 public virtual ITranslationResult Translate(ITranslatable target, string language)
 {
     ITranslationResult result = null;
     foreach (KeyValuePair<string, Control> pair in target.TranslationTargets)
     {
         if (pair.Value is ITextControl)
         {
             ITextControl textControl = pair.Value as ITextControl;
             result = this.Translate(pair.Key, textControl.Text, language);
             if (result.IsSuccessful())
             {
                 textControl.Text = result.Translation;
             }
         }
     }
     return result;
 }
 private void SetChildTranslation(ITranslatable control) {
     if (control != null) {
         control.Translator = this;
     }
 }