Help needed in creating a multi-lingual country list and displaying it in a dropdown list

Topics: General, Localization, Writing modules
Dec 4, 2013 at 8:56 PM
Edited Dec 6, 2013 at 3:23 PM
I am new to Orchard CMS, and the time I have to learn it is very limited due to the time constraints of the project I'm working on.

I am facing the following problem and I'm hoping somebody can help me find a solution. I've searched for complete examples on this forum and elsewhere but found none.

I am trying to create a list of localizable list of countries in the CMS admin, and render these countries in a drop down list in a custom view within the custom module I have created. My module is activated as a feature in the cms, but beyond that, my module does not communicate with the cms's objects. In short, it consists of a form that read/writes data to an external sql custom database, this form data is NOT to be seen or saved in the CMS.

I simply want to pull a list of countries (localizable) which would be managed through the CMS admin, and display these countries in a drop down list on my form.

Here is what I've tried so far without success:
  1. I've created a new Taxonomy called "Countries", and added a few countries as terms under that Taxonomy. I then installed the Contrib.Taxonomy module, hoping that I could access those taxonomy terms programmatically within my module/view using the TaxonomyService class (more precisely by using the GetTaxonomyByName and GetTerms Methods). But I don't know what parameter values I need to pass to TaxonomyService class constructor in order to use these methods. Having searched the documentation in vain to learn how to instanciate and use the TaxonomyService class within my custom module, I've dropped this approach.
  2. I then tried using a custom content type which I named "Countries" and added a custom Field of the "Taxonomy field" type to this content type, (the "Taxonomy field" was made available through the Contrib.Taxonomies module). However, when I tried adding new taxonomy terms to this Country content type by clicking on the "Create some terms " link, a server error appeared. I googled this error and I found one person who had the same error, albeit in a different scenario: I have not found a way to fix this error which is thrown by the Orchard module, so I stopped investigating this approach.
  3. I then installed the "Choice list field" module and added a "choice list field" to the "Country" content type I created earlier, but I've not figured out a way to add a list of countries to this "choice field list" field.
  4. I've watched the following video but found that it only gave a part of the big picture, and did not provide a complete tutorial on what I'm trying to accomplish.
If someone can pitch in and provide some insight or hopefully a complete tutorial on how to achieve this, it would be greatly appreciated.

Dec 4, 2013 at 9:35 PM
Edited Dec 4, 2013 at 9:35 PM
What about the following approach:
  1. Define a new content type called "Country", attach the LocalizablePart;
  2. Add a text field called "Name" to the content type;
  3. Create a couple of countries and their localized counter parts;
  4. Create your drop down and populate it by querying for all countries using the desired culture.
Marked as answer by Number823 on 12/6/2013 at 8:22 AM
Dec 5, 2013 at 3:57 PM
Edited Dec 5, 2013 at 4:24 PM
Thanks sfmskywalker, I initially thought of trying that method, but when using that approach, all countries added this way appear in the Country Content page as separate content entries, but they all share the same name: "Country" for all 224 countries.

There is no way of knowing which country that content is referring to. To know what country it is, a user must click on one of the "Country" contents, then the country name appears in a textbox on the detail page.

This is not user friendly at all, because if someone wants to deactivate a country, there is no way for them to know which country is which in the Country Content page, since all 224 countries have "Country" as their title.

I could maybe still implement this solution, but I would first need this scenario to be possible:
  1. A user opens the "Manage content" page
  2. The user filters the contents by "Country".
  3. The page then shows the list of countries values such as they are defined in the "name" text field, (United States, Canada, etc..), and not 224 times (Country, Country, Country, Country, Country, etc...)
Is this even possible?
Dec 5, 2013 at 4:48 PM
Edited Dec 5, 2013 at 5:12 PM
I figured out how to do what I explained in my previous post. I added a "Title" part to my "Country" content type, and added the country name in this field, so the country name now appears in the "Manage content" page.

I will now investigate how I can access these values from my view

Thanks sfmskywalker!