Example #1
0
	//-----------------------------------------------------------------------------
	/// <summary>
	/// Fill the system locales drop-down.
	/// </summary>
	private void FillLocalesCombo()
	{
		try
		{
			if (cmbLang.Items.Count != 0) return;

			Boolean found = false;
			string login = !String.IsNullOrEmpty(txtUser.Text) ? txtUser.Text : "temp";
			if (PXDatabase.Companies.Length > 0)
			{
				string company = this.Request.Form[cmbCompany.UniqueID];
				if (string.IsNullOrEmpty(company))
					company = cmbCompany.SelectedIndex != -1 ? cmbCompany.SelectedItem.Value : PXDatabase.Companies[0];
				login += "@" + company;
			}
			PXLocale[] locales = PXLocalesProvider.GetLocales(login);

			foreach (PXLocale loc in locales)
			{
				ListItem item = new ListItem(loc.DisplayName, loc.Name);
				cmbLang.Items.Add(item);
				if (!found && Request.Cookies["Locale"] != null && Request.Cookies["Locale"]["Culture"] != null &&
					string.Compare(Request.Cookies["Locale"]["Culture"], item.Value, true) == 0)
				{
					cmbLang.SelectedValue = item.Value;
					found = true;
				}
			}

			String value = this.Request.Form[cmbLang.ClientID.Replace('_', '$')];
			if (!String.IsNullOrEmpty(value) && locales.Any(l => l.Name == value))
			{
				cmbLang.SelectedValue = value;
				found = true;
			}
			if (!string.IsNullOrEmpty(Page.Request.QueryString["LocaleID"]))
			{
				String locale = Page.Request.QueryString["LocaleID"];
				if (locales.Select(l => l.Name).Contains(locale))
					this.cmbCompany.SelectedValue = locale;
			}
			if (cmbLang.Items.Count == 1) cmbLang.Style[HtmlTextWriterStyle.Display] = "none";
			else cmbLang.Style[HtmlTextWriterStyle.Display] = null;
		}
		catch
		{
			cmbLang.Visible = false;
			this.btnLogin.Visible = false;
			this.Master.Message = "Database could not be accessed";
		}
	}
Example #2
0
    //-----------------------------------------------------------------------------
    /// <summary>
    /// Fill the system locales drop-down.
    /// </summary>
    private void FillLocalesCombo()
    {
        try
        {
            if (cmbLang.Items.Count != 0)
            {
                return;
            }

            Boolean    found   = false;
            PXLocale[] locales = PXLocalesProvider.GetLocales(
                (!String.IsNullOrEmpty(txtUser.Text) ? txtUser.Text : "temp") + (PXDatabase.Companies.Length > 0 ? "@" +
                                                                                 (cmbCompany.SelectedIndex != -1 ? cmbCompany.SelectedItem.Value : PXDatabase.Companies[0]) : ""));

            foreach (PXLocale loc in locales)
            {
                ListItem item = new ListItem(loc.DisplayName, loc.Name);
                cmbLang.Items.Add(item);
                if (!found && Request.Cookies["Locale"] != null && Request.Cookies["Locale"]["Culture"] != null &&
                    string.Compare(Request.Cookies["Locale"]["Culture"], item.Value, true) == 0)
                {
                    cmbLang.SelectedValue = item.Value;
                    found = true;
                }
            }

            String value = this.Request.Form[cmbLang.ClientID.Replace('_', '$')];
            if (!String.IsNullOrEmpty(value) && locales.Any(l => l.Name == value))
            {
                cmbLang.SelectedValue = value;
                found = true;
            }
            if (cmbLang.Items.Count == 1)
            {
                cmbLang.Style[HtmlTextWriterStyle.Display] = "none";
            }
        }
        catch
        {
            cmbLang.Visible       = false;
            this.btnLogin.Visible = false;
            this.Master.Message   = "Database could not be accessed";
        }
    }
        private string GetAllTranslations(PXCache sender, string field, int i, string[] neutral, string[] theonly)
        {
            PXLocale[] locales = Common.PXContext.GetSlot <PXLocale[]>("SILocales");
            if (locales == null)
            {
                Common.PXContext.SetSlot("SILocales", locales = PXLocalesProvider.GetLocales());
            }
            if (locales.Length <= 1)
            {
                return(theonly[i]);
            }
            HashSet <string> list = new HashSet <string>();

            foreach (var locale in locales)
            {
                if (!String.Equals(locale.Name, System.Threading.Thread.CurrentThread.CurrentCulture.Name))
                {
                    using (new Common.PXCultureScope(new System.Globalization.CultureInfo(locale.Name)))
                    {
                        string[] labels = new string[neutral.Length];
                        PXLocalizerRepository.ListLocalizer.Localize(field, sender, neutral, labels);
                        if (!String.IsNullOrWhiteSpace(labels[i]))
                        {
                            list.Add(labels[i]);
                        }
                    }
                }
                else if (!String.IsNullOrWhiteSpace(theonly[i]))
                {
                    list.Add(theonly[i]);
                }
            }
            if (list.Count > 1)
            {
                return(String.Join(" ", list));
            }
            return(theonly[i]);
        }