Ejemplo n.º 1
0
        public static ITranslateProvider GetProviderFromPreferences(object [] args)
        {
            Type providerType           = Type.GetType("Translate." + ConfigUI.SelectedProvider, true);
            ITranslateProvider provider = (ITranslateProvider)System.Activator.CreateInstance(providerType, args);

            return(provider);
        }
Ejemplo n.º 2
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modItems)
        {
            ITranslateProvider Translator = TranslateEngine.Translator;
            string             url        = null;
            LanguageItem       ToLang     = (modItems.First() as LanguageItem);

            foreach (Item i in items)
            {
                if (i is ITextItem)
                {
                    if (Translator.SupportsUrlTranslate && url_regex.IsMatch((i as ITextItem).Text))
                    {
                        url = Translator.BuildUrlRequestUrl(ConfigUI.SelectedIfaceLang, ToLang.Code, ConfigUI.SelectedSourceLang, (i as ITextItem).Text);
                    }
                    else
                    {
                        url = Translator.BuildTextRequestUrl(ConfigUI.SelectedIfaceLang, ToLang.Code, ConfigUI.SelectedSourceLang, (i as ITextItem).Text);
                    }
                }
                if (i is IUrlItem)
                {
                    url = Translator.BuildUrlRequestUrl(ConfigUI.SelectedIfaceLang, ToLang.Code, ConfigUI.SelectedSourceLang, (i as IUrlItem).Url);
                }
                if (i is IFileItem)
                {
                    url = Translator.BuildTextRequestUrl(ConfigUI.SelectedIfaceLang, ToLang.Code, ConfigUI.SelectedSourceLang, File.ReadAllText((i as IFileItem).Path));
                }

                if (!string.IsNullOrEmpty(url))
                {
                    Services.Environment.OpenUrl(url);
                }
            }
            yield break;
        }
Ejemplo n.º 3
0
        public override bool SupportsItem(Item item)
        {
            ITranslateProvider Translator = TranslateEngine.Translator;

            if (item is IFileItem)
            {
                IFileItem file = item as IFileItem;
                if (Directory.Exists(file.Path))
                {
                    return(false);
                }
                long kbSize = new FileInfo(file.Path).Length / 1024;
                return(kbSize < 100);
            }
            if (item is ITextItem)
            {
                if (!Translator.SupportsUrlTranslate && url_regex.IsMatch((item as ITextItem).Text))
                {
                    return(false);
                }
            }
            if (item is IUrlItem && !Translator.SupportsUrlTranslate)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
 public GenreService(IUnitOfWork unitOfWork,
                     IMongoLogger logRepository,
                     ITranslateProvider <GenreTranslation, Genre> genreTranslation) : base(logRepository)
 {
     _language         = CultureInfo.CurrentCulture.Name;
     _unitOfWork       = unitOfWork;
     _genreTranslation = genreTranslation;
     _genreRepository  = _unitOfWork.GetRepository <ICrudRepository <Genre> >();
 }
Ejemplo n.º 5
0
        public override IEnumerable <Item> DynamicModifierItemsForItem(Item item)
        {
            ITranslateProvider Translator = TranslateEngine.Translator;

            foreach (LanguageItem Language in Translator.SupportedLanguages)
            {
                yield return(Language);
            }
        }
Ejemplo n.º 6
0
 public PublisherService(IUnitOfWork unitOfWork,
                         IMongoLogger logRepository,
                         ITranslateProvider <PublisherTranslation, Publisher> publisherTranslate) : base(logRepository)
 {
     _language            = CultureInfo.CurrentCulture.Name;
     _unitOfWork          = unitOfWork;
     _publisherTranslate  = publisherTranslate;
     _publisherRepository = _unitOfWork.GetRepository <ICrudRepository <Publisher> >();
 }
Ejemplo n.º 7
0
 public PlatformService(IUnitOfWork unitOfWork,
                        IMongoLogger logRepository,
                        ITranslateProvider <PlatformTranslation, Platform> platformTranslate) : base(logRepository)
 {
     _language           = CultureInfo.CurrentCulture.Name;
     _unitOfWork         = unitOfWork;
     _platformTranslate  = platformTranslate;
     _platformRepository = _unitOfWork.GetRepository <ICrudRepository <Platform> >();
 }
Ejemplo n.º 8
0
 public GameService(IUnitOfWork unitOfWork,
                    IMongoLogger logRepository,
                    ITranslateProvider <GameTranslation, Game> gameTranslate,
                    IGameRepository gameRepository) : base(logRepository)
 {
     _language            = CultureInfo.CurrentCulture.Name;
     _unitOfWork          = unitOfWork;
     _gameTranslate       = gameTranslate;
     _gameRepository      = gameRepository;
     _genreRepository     = unitOfWork.GetRepository <ICrudRepository <Genre> >();
     _publisherRepository = unitOfWork.GetRepository <ICrudRepository <Publisher> >();
 }
Ejemplo n.º 9
0
        public void FillSourceCmb(ITranslateProvider Translator)
        {
            cmbDefaultSource.Clear();

            Gtk.CellRendererText   cell   = new Gtk.CellRendererText();
            Gtk.CellRendererPixbuf pixbuf = new Gtk.CellRendererPixbuf();
            cmbDefaultSource.PackStart(pixbuf, true);
            cmbDefaultSource.PackStart(cell, true);
            cmbDefaultSource.AddAttribute(pixbuf, "pixbuf", 0);
            cmbDefaultSource.AddAttribute(cell, "text", 1);


            Gtk.ListStore SourceList = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string));

            Gdk.Pixbuf LanguageFlag = null;
            const int  scale_height = 20;

            string[] Icon = null;
            if (Translator.SupportsAutoDetect)
            {
                SourceList.AppendValues(null, AddinManager.CurrentLocalizer.GetString("Auto Detect (Recommended)"), Translator.AutoDetectCode);
            }
            foreach (LanguageItem Lang in Translator.SupportedLanguages)
            {
                Icon = Lang.Icon.Split(new char[] { '@' });
                using (Gdk.Pixbuf temp = Gdk.Pixbuf.LoadFromResource(Icon[0])) {
                    LanguageFlag = temp.ScaleSimple((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
                }
                SourceList.AppendValues(LanguageFlag, Lang.Name, Lang.Code);
            }

            cmbDefaultSource.Model = SourceList;
            //set default source to auto if it's enabled, else try what's in gconf, else, just the first in the list
            Gtk.TreeIter ti;
            if ((Translator.SupportsAutoDetect) && (SearchCombobox(out ti, cmbDefaultSource, Translator.AutoDetectCode, 2)))
            {
                cmbDefaultSource.SetActiveIter(ti);
            }
            else if (SearchCombobox(out ti, cmbDefaultSource, SelectedSourceLang, 2))
            {
                cmbDefaultSource.SetActiveIter(ti);
            }
            else
            {
                cmbDefaultSource.Model.GetIterFirst(out ti);
                cmbDefaultSource.SetActiveIter(ti);
            }
        }
Ejemplo n.º 10
0
        private void FillEnableBox(ITranslateProvider Translator)
        {
            Gtk.ListStore LanguageList = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string));
            const int     scale_height = 25;

            Gdk.Pixbuf LanguageFlag = null;
            string[]   Icon         = null;

            foreach (LanguageItem Lang in Translator.SupportedLanguages)
            {
                Icon = Lang.Icon.Split(new char[] { '@' });
                using (Gdk.Pixbuf temp = Gdk.Pixbuf.LoadFromResource(Icon[0])) {
                    LanguageFlag = temp.ScaleSimple((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
                }
                LanguageList.AppendValues(LanguageFlag, Lang.Name);
            }

            treeEnableLang.HeadersVisible = false;
            treeEnableLang.Model          = LanguageList;
        }
Ejemplo n.º 11
0
        protected virtual void ProviderSelectionChanged(object sender, System.EventArgs e)
        {
            Gtk.ComboBox ProviderBox = (Gtk.ComboBox)sender;
            Gtk.TreeIter ti;
            ProviderBox.GetActiveIter(out ti);
            SelectedProvider = (string)ProviderBox.Model.GetValue(ti, 1);
            TranslateEngine.LoadValuesFromPrefs();
            ITranslateProvider Translator = TranslateEngine.Translator;

            //fill boxes
            FillSourceCmb(Translator);
            if (Translator.SupportsIfaceLang)
            {
                FillIfaceCmb(Translator);
            }
            else
            {
                cmbDefaultIface.Clear();
                cmbDefaultIface.Model = null;
            }
            FillEnableBox(Translator);
        }
Ejemplo n.º 12
0
        private void FillIfaceCmb(ITranslateProvider Translator)
        {
            cmbDefaultIface.Clear();

            Gtk.CellRendererText   cell   = new Gtk.CellRendererText();
            Gtk.CellRendererPixbuf pixbuf = new Gtk.CellRendererPixbuf();
            cmbDefaultIface.PackStart(pixbuf, true);
            cmbDefaultIface.PackStart(cell, true);
            cmbDefaultIface.AddAttribute(pixbuf, "pixbuf", 0);
            cmbDefaultIface.AddAttribute(cell, "text", 1);

            Gtk.ListStore IfaceList = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string));

            Gdk.Pixbuf LanguageFlag = null;
            const int  scale_height = 20;

            string[] Icon = null;
            foreach (LanguageItem Lang in Translator.SupportedLanguages)
            {
                Icon = Lang.Icon.Split(new char[] { '@' });
                using (Gdk.Pixbuf temp = Gdk.Pixbuf.LoadFromResource(Icon[0])) {
                    LanguageFlag = temp.ScaleSimple((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
                }
                IfaceList.AppendValues(LanguageFlag, Lang.Name, Lang.Code);
            }

            cmbDefaultIface.Model = IfaceList;
            //set selection to what's in GConf, if we can
            Gtk.TreeIter ti;
            if (SearchCombobox(out ti, cmbDefaultIface, SelectedIfaceLang, 2))
            {
                cmbDefaultIface.SetActiveIter(ti);
            }
            else
            {
                cmbDefaultIface.Model.GetIterFirst(out ti);
                cmbDefaultIface.SetActiveIter(ti);
            }
        }
Ejemplo n.º 13
0
        private void FillIfaceCmb(ITranslateProvider Translator)
        {
            cmbDefaultIface.Clear ();

            Gtk.CellRendererText cell = new Gtk.CellRendererText ();
            Gtk.CellRendererPixbuf pixbuf = new Gtk.CellRendererPixbuf ();
            cmbDefaultIface.PackStart (pixbuf, true);
            cmbDefaultIface.PackStart (cell, true);
            cmbDefaultIface.AddAttribute (pixbuf, "pixbuf" , 0);
            cmbDefaultIface.AddAttribute (cell, "text", 1);

            Gtk.ListStore IfaceList = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof (string), typeof (string));

            Gdk.Pixbuf LanguageFlag = null;
            const int scale_height = 20;
            string[] Icon = null;
            foreach (LanguageItem Lang in Translator.SupportedLanguages) {
                Icon = Lang.Icon.Split(new char[] {'@'});
                using (Gdk.Pixbuf temp = Gdk.Pixbuf.LoadFromResource(Icon[0])) {
                    LanguageFlag = temp.ScaleSimple ((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
                }
                IfaceList.AppendValues (LanguageFlag, Lang.Name, Lang.Code);
            }

            cmbDefaultIface.Model = IfaceList;
            //set selection to what's in GConf, if we can
            Gtk.TreeIter ti;
            if (SearchCombobox (out ti, cmbDefaultIface, SelectedIfaceLang, 2))
                cmbDefaultIface.SetActiveIter(ti);
            else {
                cmbDefaultIface.Model.GetIterFirst (out ti);
                cmbDefaultIface.SetActiveIter (ti);
            }
        }
Ejemplo n.º 14
0
 internal TranslateScope(IContextService service, ITranslateProvider translator, TranslateOptions options)
 {
     ContextService = service;
     Translator     = translator;
     Options        = options;
 }
Ejemplo n.º 15
0
 internal TranslateScope(InternalContext context, ITranslateProvider translator, TranslateOptions options)
 {
     Context    = context;
     Translator = translator;
     Options    = options;
 }
Ejemplo n.º 16
0
        private void FillEnableBox(ITranslateProvider Translator)
        {
            Gtk.ListStore LanguageList = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof (string));
            const int scale_height = 25;
            Gdk.Pixbuf LanguageFlag = null;
            string[] Icon = null;

            foreach (LanguageItem Lang in Translator.SupportedLanguages) {
                Icon = Lang.Icon.Split (new char[] {'@'});
                using (Gdk.Pixbuf temp = Gdk.Pixbuf.LoadFromResource(Icon[0])) {
                    LanguageFlag = temp.ScaleSimple ((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
                }
                LanguageList.AppendValues (LanguageFlag, Lang.Name);
            }

            treeEnableLang.HeadersVisible = false;
            treeEnableLang.Model = LanguageList;
        }
Ejemplo n.º 17
0
        public void FillSourceCmb(ITranslateProvider Translator)
        {
            cmbDefaultSource.Clear ();

            Gtk.CellRendererText cell = new Gtk.CellRendererText ();
            Gtk.CellRendererPixbuf pixbuf = new Gtk.CellRendererPixbuf ();
            cmbDefaultSource.PackStart( pixbuf, true);
            cmbDefaultSource.PackStart (cell, true);
            cmbDefaultSource.AddAttribute (pixbuf, "pixbuf" , 0);
            cmbDefaultSource.AddAttribute (cell, "text", 1);

            Gtk.ListStore SourceList = new Gtk.ListStore (typeof (Gdk.Pixbuf), typeof (string), typeof (string));

            Gdk.Pixbuf LanguageFlag = null;
            const int scale_height = 20;
            string[] Icon = null;
            if (Translator.SupportsAutoDetect)
                SourceList.AppendValues (null, AddinManager.CurrentLocalizer.GetString ("Auto Detect (Recommended)"), Translator.AutoDetectCode);
            foreach (LanguageItem Lang in Translator.SupportedLanguages)
            {
                Icon = Lang.Icon.Split (new char[] {'@'});
                using (Gdk.Pixbuf temp = Gdk.Pixbuf.LoadFromResource (Icon[0])) {
                    LanguageFlag = temp.ScaleSimple ((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
                }
                SourceList.AppendValues (LanguageFlag, Lang.Name, Lang.Code);
            }

            cmbDefaultSource.Model = SourceList;
            //set default source to auto if it's enabled, else try what's in gconf, else, just the first in the list
            Gtk.TreeIter ti;
            if ((Translator.SupportsAutoDetect) && (SearchCombobox (out ti, cmbDefaultSource, Translator.AutoDetectCode, 2)))
                cmbDefaultSource.SetActiveIter (ti);
            else if (SearchCombobox(out ti, cmbDefaultSource, SelectedSourceLang, 2))
                cmbDefaultSource.SetActiveIter (ti);
            else {
                cmbDefaultSource.Model.GetIterFirst (out ti);
                cmbDefaultSource.SetActiveIter (ti);
            }
        }
Ejemplo n.º 18
0
 public TranslateScope(InternalContext context, ITranslateProvider translator)
 {
     Context    = context;
     Translator = translator;
 }
Ejemplo n.º 19
0
 public static void LoadValuesFromPrefs()
 {
     Translator = TranslateProviderFactory.GetProviderFromPreferences();
 }
Ejemplo n.º 20
0
 public TranslateMarkdown(TranslateOptions options)
 {
     this.Parser   = new MarkdownParser();
     this.Provider = TranslateProviderFactory.CreateProvider(options);
 }