Ejemplo n.º 1
0
        /// <summary>
        /// Get all time zones.
        /// </summary>
        /// <param name="forceLanguage">
        /// The force language.
        /// </param>
        /// <returns>
        /// Returns a Data Table with all time zones.
        /// </returns>
        public static DataTable TimeZones(string forceLanguage)
        {
            var localization = new YafLocalization();

            localization.LoadTranslation(forceLanguage);

            return(TimeZones(localization));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all country names list(localized).
        /// </summary>
        /// <param name="forceLanguage">
        /// The force a specific language.
        /// </param>
        /// <returns>
        /// Returns a Data Table with all country names list(localized)
        /// </returns>
        public static DataTable Country(string forceLanguage)
        {
            var localization = new YafLocalization();

            localization.LoadTranslation(forceLanguage);

            return(Country(localization));
        }
Ejemplo n.º 3
0
    /// <summary>
    /// The get text, with a Specific Language.
    /// </summary>
    /// <param name="page">
    /// The page.
    /// </param>
    /// <param name="tag">
    /// The tag.
    /// </param>
    /// <param name="languageFile">
    /// The Language file
    /// </param>
    /// <returns>
    /// The get text.
    /// </returns>
    public string GetText([NotNull] string page, [NotNull] string tag, [NotNull] string languageFile)
    {
      string localizedText;

      if (!string.IsNullOrEmpty(languageFile))
      {
        var localization = new YafLocalization();
        localization.LoadTranslation(languageFile);
        localizedText = localization.GetText(page, tag);
      }
      else
      {
        localizedText = this.GetLocalizedTextInternal(page, tag);
      }

      if (localizedText == null)
      {
#if !DEBUG
            string filename;

            if (!string.IsNullOrEmpty(languageFile))
            {
                filename = languageFile;
            }
            else
            {
                if (YafContext.Current.PageIsNull() ||
                 YafContext.Current.LanguageFile == string.Empty ||
                 YafContext.Current.LanguageFile == string.Empty ||
                 !YafContext.Current.Get<YafBoardSettings>().AllowUserLanguage)
                {
                    filename = YafContext.Current.Get<YafBoardSettings>().Language;
                }
                else
                {
                    filename = YafContext.Current.LanguageFile;
                }
            }
            

            if (filename == string.Empty) filename = "english.xml";

            HttpContext.Current.Cache.Remove("Localizer." + filename);
#endif
          CommonDb.eventlog_create(YafContext.Current.PageModuleID, YafContext.Current.PageUserID, 
          page.ToLower() + ".ascx", 
          "Missing Translation For {1}.{0}".FormatWith(tag.ToUpper(), page.ToUpper()), 
          EventLogTypes.Error);
        return "[{1}.{0}]".FormatWith(tag.ToUpper(), page.ToUpper());
      }

      localizedText = localizedText.Replace("[b]", "<b>");
      localizedText = localizedText.Replace("[/b]", "</b>");

      return localizedText;
    }
Ejemplo n.º 4
0
        private static MemoryStream GetAlbumOrAttachmentImageResized(
            [NotNull] Stream data,
            int previewWidth,
            int previewHeight,
            bool previewCropped,
            int downloads,
            [NotNull] string localizationFile,
            string localizationPage)
        {
            const int PixelPadding = 6;
            const int BottomSize = 26;

            var localization = new YafLocalization(localizationPage);
            localization.LoadTranslation(localizationFile);

            using (var src = new Bitmap(data))
            {
                var ms = new MemoryStream();

                // Cropped Image
                int size = previewWidth;

                var newImgSize = new Size(previewWidth, previewHeight);
                int x = 0;
                int y = 0;

                if (previewCropped)
                {
                    // Determine dimensions of resized version of the image 
                    if (newImgSize.Width > newImgSize.Height)
                    {
                        newImgSize.Width =
                            decimal.Round(
                                (size.ToType<decimal>()
                                 * (newImgSize.Width.ToType<decimal>() / newImgSize.Height.ToType<decimal>())).ToType<decimal>(),
                                0).ToType<int>();
                        newImgSize.Height = size;
                    }
                    else if (newImgSize.Height > newImgSize.Width)
                    {
                        newImgSize.Height =
                            decimal.Round(
                                (size.ToType<decimal>()
                                 * (newImgSize.Height.ToType<decimal>() / newImgSize.Width.ToType<decimal>())).ToType<decimal>(),
                                0).ToType<int>();
                        newImgSize.Width = size;
                    }
                    else
                    {
                        newImgSize.Width = size;
                        newImgSize.Height = size;
                    }

                    newImgSize.Width = newImgSize.Width - PixelPadding;
                    newImgSize.Height = newImgSize.Height - BottomSize - PixelPadding;

                    // moves cursor so that crop is more centered 
                    x = newImgSize.Width / 2;
                    y = newImgSize.Height / 2;
                }
                else
                {
                    var finalHeight = Math.Abs(src.Height * newImgSize.Width / src.Width);

                    // Height resize if necessary
                    if (finalHeight > newImgSize.Height)
                    {
                        newImgSize.Width = src.Width * newImgSize.Height / src.Height;
                        finalHeight = newImgSize.Height;
                    }

                    newImgSize.Height = finalHeight;
                    newImgSize.Width = newImgSize.Width - PixelPadding;
                    newImgSize.Height = newImgSize.Height - BottomSize - PixelPadding;

                    if (newImgSize.Height <= BottomSize + PixelPadding)
                    {
                        newImgSize.Height = finalHeight;
                    }
                }

                bool heightToSmallFix = newImgSize.Height <= BottomSize + PixelPadding;

                using (
                    var dst = new Bitmap(
                        newImgSize.Width + PixelPadding,
                        newImgSize.Height + BottomSize + PixelPadding,
                        PixelFormat.Format24bppRgb))
                {
                    var rSrcImg = new Rectangle(
                        0, 0, src.Width, src.Height + (heightToSmallFix ? BottomSize + PixelPadding : 0));

                    if (previewCropped)
                    {
                        rSrcImg = new Rectangle(x, y, newImgSize.Width, newImgSize.Height);
                    }

                    var rDstImg = new Rectangle(3, 3, dst.Width - PixelPadding, dst.Height - PixelPadding - BottomSize);
                    var rDstTxt1 = new Rectangle(3, rDstImg.Height + 3, newImgSize.Width, BottomSize - 13);
                    var rDstTxt2 = new Rectangle(3, rDstImg.Height + 16, newImgSize.Width, BottomSize - 13);

                    using (Graphics g = Graphics.FromImage(dst))
                    {
                        g.Clear(Color.FromArgb(64, 64, 64));
                        g.FillRectangle(Brushes.White, rDstImg);

                        g.CompositingMode = CompositingMode.SourceOver;
                        g.CompositingQuality = CompositingQuality.GammaCorrected;
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                        g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                        g.DrawImage(src, rDstImg, rSrcImg, GraphicsUnit.Pixel);

                        using (var f = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel))
                        {
                            using (var brush = new SolidBrush(Color.FromArgb(191, 191, 191)))
                            {
                                var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center };

                                g.DrawString(localization.GetText("IMAGE_RESIZE_ENLARGE"), f, brush, rDstTxt1, sf);

                                sf.Alignment = StringAlignment.Far;
                                g.DrawString(
                                    localization.GetText("IMAGE_RESIZE_VIEWS").FormatWith(downloads),
                                    f,
                                    brush,
                                    rDstTxt2,
                                    sf);
                            }
                        }
                    }

                    // save the bitmap to the stream...
                    dst.Save(ms, ImageFormat.Png);
                    ms.Position = 0;

                    return ms;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The get text, with a Specific Language.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="tag">
        /// The tag.
        /// </param>
        /// <param name="languageFile">
        /// The Language file
        /// </param>
        /// <returns>
        /// The get text.
        /// </returns>
        public string GetText([NotNull] string page, [NotNull] string tag, [NotNull] string languageFile)
        {
            string localizedText;

            if (!string.IsNullOrEmpty(languageFile))
            {
                var localization = new YafLocalization();
                localization.LoadTranslation(languageFile);
                localizedText = localization.GetText(page, tag);
            }
            else
            {
                localizedText = this.GetLocalizedTextInternal(page, tag);
            }

            if (localizedText == null)
            {
#if !DEBUG
                string filename;

                if (!string.IsNullOrEmpty(languageFile))
                {
                    filename = languageFile;
                }
                else
                {
                    if (YafContext.Current.PageIsNull() ||
                        YafContext.Current.LanguageFile == string.Empty ||
                        YafContext.Current.LanguageFile == string.Empty ||
                        !YafContext.Current.Get <YafBoardSettings>().AllowUserLanguage)
                    {
                        filename = YafContext.Current.Get <YafBoardSettings>().Language;
                    }
                    else
                    {
                        filename = YafContext.Current.LanguageFile;
                    }
                }


                if (filename == string.Empty)
                {
                    filename = "english.xml";
                }

                HttpContext.Current.Cache.Remove("Localizer." + filename);
#endif
                YafContext.Current.Get <ILogger>()
                .Log(
                    YafContext.Current.PageUserID,
                    page.ToLower() + ".ascx",
                    "Missing Translation For {1}.{0}".FormatWith(tag.ToUpper(), page.ToUpper()),
                    EventLogTypes.Error);

                return("[{1}.{0}]".FormatWith(tag.ToUpper(), page.ToUpper()));
            }

            localizedText = localizedText.Replace("[b]", "<b>");
            localizedText = localizedText.Replace("[/b]", "</b>");

            return(localizedText);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads a template from the language file
        /// </summary>
        /// <param name="templateName">
        /// The template Name.
        /// </param>
        /// <param name="templateLanguageFile">
        /// The template Language File.
        /// </param>
        /// <returns>
        /// The template
        /// </returns>
        private string ReadTemplate(string templateName, string templateLanguageFile)
        {
            if (templateName.IsSet())
            {
                if (!templateLanguageFile.IsSet())
                    return YafContext.Current.Get<ILocalization>().GetText("TEMPLATES", templateName);
               
                var localization = new YafLocalization();
                localization.LoadTranslation(templateLanguageFile);
                return localization.GetText("TEMPLATES", templateName);
            }

            return null;
        }