Contributions to translations (nopCommerce v1.10)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 anni tempo fa
Please save your changes in utf-8 encoding
15 anni tempo fa
Hi,
I'm translating NopCommerce to Turkish. I will send the filesfor 2 or 3 days.
15 anni tempo fa
on IST 5th eve you will have all hi-IN
15 anni tempo fa
Hi,
I'm translating NopCommerce to Italian. I will send tommorow.
15 anni tempo fa
Hello, all!
I will translate for nopCommerce to Norwegian language.
Be well!

Anders
15 anni tempo fa
Hi,
Is there a way to import the contributed languages (the RAR file) to nopCommerce? Or do we have to wait for you to implement it into the installation package?
15 anni tempo fa
We have written a small application to import the contributed languages (will be integrated in the next release):



class Program
    {
        private static Encoding encoding = Encoding.UTF8;

        static void Main(string[] args)
        {
            try
            {
                //your language id here
                int LanguageID = 123456;

                string ConnectionString = "Data Source=ANDREY-M;Initial Catalog=nopCommerce;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=dgs2002;Connect Timeout=120";
                string ResourcePackagePath = @"path_to_directory_with_your_resources";

                
                
                    string ResourceStringFilePath = Path.Combine(ResourcePackagePath, "ResourceStrings.xml");
                    Dictionary<string, string> resources = GetResources(ResourceStringFilePath);
                    SaveResourceStrings(LanguageID, ConnectionString, resources);
                

                
                    List<string> templateNames = new List<string>();
                    templateNames.Add("Customer.EmailValidationMessage");
                    templateNames.Add("Customer.PasswordRecovery");
                    templateNames.Add("Customer.WelcomeMessage");
                    templateNames.Add("OrderCancelled.CustomerNotification");
                    templateNames.Add("OrderCompleted.CustomerNotification");
                    templateNames.Add("OrderPlaced.CustomerNotification");
                    templateNames.Add("OrderPlaced.StoreOwnerNotification");
                    templateNames.Add("OrderShipped.CustomerNotification");
                    templateNames.Add("Service.EmailAFriend");

                    foreach (string templateName in templateNames)
                    {
                        string templateFilePath = Path.Combine(path, templateName + ".txt");
                        string templateSubject = string.Empty;
                        string templateBody = string.Empty;
                        GetMessageTemplateContent(templateFilePath, out templateSubject, out templateBody);
                        SaveMessageTemplate(LanguageID, ConnectionString, templateName, templateSubject, templateBody);
                    }
                
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.ToString());
            }
            finally
            {
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
        }

        static Dictionary<string, string> GetResources(string FilePath)
        {
            Dictionary<string, string> resources = new Dictionary<string, string>();
            string Xml = File.ReadAllText(FilePath, encoding);

            StringReader _sr = new StringReader(Xml);
            XmlTextReader _xtr = new XmlTextReader(_sr);
            _xtr.XmlResolver = null;
            _xtr.WhitespaceHandling = WhitespaceHandling.None;
            _xtr.Read();

            if ((_xtr.NodeType == XmlNodeType.Element) && (_xtr.Name == "Language"))
            {
                while (_xtr.Read())
                {
                    if ((_xtr.NodeType == XmlNodeType.Element) && (_xtr.Name == "LocaleResource"))
                    {
                        string resourceName = _xtr["Name"];

                        _xtr.Read();
                        if ((_xtr.NodeType == XmlNodeType.Element) && (_xtr.Name == "Value"))
                        {
                            _xtr.Read();
                            if (_xtr.NodeType == XmlNodeType.Text)
                            {
                                string resourceValue = _xtr.Value;
                                resources.Add(resourceName, resourceValue);
                            }
                        }
                    }
                }
            }

            return resources;
        }

        static void SaveResourceStrings(int LanguageID, string ConnectionString, Dictionary<string, string> resources)
        {
            foreach (KeyValuePair<string, string> kvp in resources)
            {
                string resourceName = kvp.Key;
                string resourceValue = kvp.Value;
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    SqlCommand command = new SqlCommand("Nop_LocaleStringResourceInsert", conn);
                    command.CommandType = CommandType.StoredProcedure;
                    SqlParameter paramLocaleStringResourceID = new SqlParameter("@LocaleStringResourceID", DBNull.Value);
                    command.Parameters.Add(paramLocaleStringResourceID);
                    SqlParameter paramLanguageID = new SqlParameter("@LanguageID", LanguageID);
                    command.Parameters.Add(paramLanguageID);
                    SqlParameter paramResourceName = new SqlParameter("@ResourceName", resourceName);
                    command.Parameters.Add(paramResourceName);
                    SqlParameter paramResourceValue = new SqlParameter("@ResourceValue", resourceValue);
                    command.Parameters.Add(paramResourceValue);
                    conn.Open();
                    command.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }

        static void GetMessageTemplateContent(string TemplateFilePath, out string templateSubject, out string templateBody)
        {
            string[] lines = File.ReadAllLines(TemplateFilePath, encoding);

            templateSubject = lines[0];

            int templateBodyStartLineNumber = 1;
            while (String.IsNullOrEmpty(lines[templateBodyStartLineNumber]))
                templateBodyStartLineNumber++;

            StringBuilder sb = new StringBuilder();
            for (int i = templateBodyStartLineNumber; i < lines.Length; i++)
            {
                sb.Append(lines[i]);
                if (i != lines.Length - 1)
                    sb.Append(Environment.NewLine);
            }

            templateBody = sb.ToString();

        }

        static void SaveMessageTemplate(int LanguageID, string ConnectionString,
            string templateName, string templateSubject, string templateBody)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                int MessageTemplateID = 0;
                string MessageTemplateName = string.Empty;


                SqlCommand getCommand = new SqlCommand("Nop_MessageTemplateLoadAll", conn);
                getCommand.CommandType = CommandType.StoredProcedure;
                conn.Open();
                SqlDataReader rdr = getCommand.ExecuteReader();
                while (rdr.Read())
                {
                    int _messageTemplateID = Convert.ToInt32(rdr["MessageTemplateID"]);
                    string _messageTemplateName = Convert.ToString(rdr["Name"]);
                    if (_messageTemplateName.ToLower() == templateName.ToLower())
                    {
                        MessageTemplateID = _messageTemplateID;
                        MessageTemplateName = _messageTemplateName;
                    }
                }
                conn.Close();




                if (MessageTemplateName.ToLower() == templateName.ToLower())
                {
                    SqlCommand saveCommand = new SqlCommand("Nop_MessageTemplateLocalizedInsert", conn);
                    saveCommand.CommandType = CommandType.StoredProcedure;
                    SqlParameter saveMessageTemplateLocalizedID = new SqlParameter("@MessageTemplateLocalizedID", DBNull.Value);
                    saveCommand.Parameters.Add(saveMessageTemplateLocalizedID);
                    SqlParameter paramMessageTemplateID = new SqlParameter("@MessageTemplateID", MessageTemplateID);
                    saveCommand.Parameters.Add(paramMessageTemplateID);
                    SqlParameter paramLanguageID = new SqlParameter("@LanguageID", LanguageID);
                    saveCommand.Parameters.Add(paramLanguageID);
                    SqlParameter paramSubject = new SqlParameter("@Subject", templateSubject);
                    saveCommand.Parameters.Add(paramSubject);
                    SqlParameter paramBody = new SqlParameter("@Body", templateBody);
                    saveCommand.Parameters.Add(paramBody);
                    conn.Open();
                    saveCommand.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }

    }
15 anni tempo fa
Thanks a lot. This is grat news!!
15 anni tempo fa
I started the translation in Portuguese - Brazil and the shipping with brazilian postal code too.
15 anni tempo fa
I'll send the language pack in Portuguese Brazil (PT-BR) for this community this week.

Sincerely...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.