IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Add WPML “Flags Only” Language Switcher to Your Navigation

The WordPress Multilingual Plugin (WPML) is a really useful plugin to build multilingual websites, however the default language switcher is not always placed neatly on the layout. After searching on WPML’s website, I ran across the page that explains how to customize the language selector with flags only:

Custom Language Switcher WPML

Now I have another problem because I wanted to place the flag language selector on the right side of my navigation menu using StudioPress Theme and I don’t have quite a good grasp of its framework yet. Luckily, Bill Erickson has a very good tutorial on how to customize/add content to its navigation:

How to Add Content to Your Navigation

From the two tutorials above, here are all the combined steps I took. Essentially, I just needed to modify two files from my Genesis child theme.

1. functions.php file:

add_filter( 'genesis_nav_items' , 'flags_selector' , 10 , 2 );
add_filter( 'wp_nav_menu_items' , 'flags_selector' , 10 , 2 );
function flags_selector($menu, $args){
  $args = (array)$args;
  $flags = '';

  if ( $args['theme_location'] != 'primary' )
    return $menu;

  $lang = icl_get_languages('skip_missing=0&orderby=code');
  if( !empty($lang) ) {
    $flags .= '<div id="flags-selector">';
    foreach( $lang as $l ) {
      $flags .= '<div class="flag-item">';
      if( !$l['active'] )
        $flags .= '<a href="' . $l['url']. '">';
      $flags .= '<img src="'. $l['country_flag_url']
                . '" height="12" alt="' . $l['language_code']
                . '" width="18" title="' . $l['translated_name']
                . '" />';
      if ( !$l['active'] )
        $flags .= '</a>';
      $flags .= '</div>';
    }
    $flags .= '</div>';
  }
  return $menu . $flags;
}

2. The CSS:

/***** Flags Only Language Selector *****/
#flags-selector {
  float: right;
  padding-top: 10px;
  }

.flag-item {
  display: inline;
  padding: 4px;
  }

The final result with the flags placed neatly on the right side of the navigation bar, can be seen on the graphic below (Agency Child Theme from Genesis Framework is used for this demo):

WPML Flags Only Language Selector on Genesis Agency Child Theme

December 12, 2011 Filed Under: How To, WordPress Tagged With: Genesis Framework

Map Model Classes to Differently Named Tables in Entity Framework

For a few days, I kept running into this minor but annoying issue using EF 4.2 with MVC3 where the web application refused to map a class (Profile) to an existing table (tblProfile) in a database [CPDB] and instead created a brand new table with the same name on a different database [CPDB.Domain.Entities.ProfileEntities].

What confused me even more was I did this step before for another class (CarAssignment) and it didn’t cause any problems. It took me a while before I figured out the small difference on how I setup the two entities.

CarAssignment.cs

namespace CPDB.Domain.Entities
{
   [Table("tblCar")]
   public class CarAssignment
   {
      [Key]
      public int CarId { get; set; }
      [StringLength(25)]
      public string CompanyType { get; set; }
      [...]
   }
}

Profile.cs

namespace CPDB.Domain.Entities
{
   [Table("tblProfile")]
   public class Profile
   {
      [Key]
      public int ProfileId { get; set; }
      [Required]
      [StringLength(30), Display(Name = "First name")]
      public string FirstName { get; set; }
      [...]

SqlCarAssignmentRepository.cs

namespace CPDB.Domain.Concrete
{
   public class SqlCarAssignmentsRepository
       : ICarAssignmentsRepository
   {
      private CarEntities db = new CarEntities();
      [...]

SqlProfileRepository.cs

namespace CPDB.Domain.Concrete
{
   public class SqlProfilesRepository : IProfilesRepository
   {
      private ProfileEntities db = new ProfileEntities();

      private IQueryable<Profile> ProfilesTable;
      [...]

NinjectControllerFactory.cs

namespace CPDB.WebUI.Infrastructure
{
   public class NinjectControllerFactory : DefaultControllerFactory
   {
      private IKernel kernel =
          new StandardKernel(new AMPServices());

      protected override IController GetControllerInstance(
          RequestContext requestContext,
          Type controllerType)
      {
         if (controllerType == null)
            return null;
         return (IController)kernel.Get(controllerType);
      }

      private class AMPServices : NinjectModule
      {
         public override void Load()
         {
            Bind()
            .To()
            .WithConstructorArgument("connectionString",
            ConfigurationManager.ConnectionStrings["CarEntities"]
            .ConnectionString);

            Bind()
            .To()
            .WithConstructorArgument("connectionStrings",
            ConfigurationManager.ConnectionStrings["DifferentName"]
            .ConnectionString);
         }
      }
   }
}

ConnectionStrings in Web.config file:

<connectionStrings>
  <add name="DifferentName" connectionString="Server=.SQLEXPRESS;
       Database=CPDB;Trusted_Connection=yes"
       providerName="System.Data.SqlClient" />
</connectionStrings>

If we just stop here, the web application will create a new table dbo.tblProfile in a new database. In order to use an existing table and database, I had to add line 8-10 on ProfileEntities class.

CarEntities.cs

namespace CPDB.Domain.Entities
{
   public class CarEntities : DbContext
   {
      public DbSet<CarAssignment> CarAssignments { get; set; }
   }
}

ProfileEntities.cs

namespace CPDB.Domain.Entities
{
   public class ProfileEntities : DbContext
   {
      public ProfileEntities()
         : base("DifferentName")
      { }

      public DbSet<Profile> Profiles { get; set; }
   }
}

If you want to use a different name, you need to alter the constructor on the DbContext. You don’t have to necessarily specify the physical database name, instead, you can use your connection strings parameter in the Web.Config file.

November 20, 2011 Filed Under: .NET, How To Tagged With: Internet, MVC

How to Upload an Album with Different Artists to Amazon Cloud Drive

Amazon Cloud Drive can do an amazing job in organizing your MP3 uploads according to the album and artists, sometimes though when you upload your existing MP3 collections, its MP3 uploader may fail to recognize songs with different artists from the same album. Just an example here, I uploaded a collection of songs from an old CD Lifescapes: Relaxing Classical I converted a few years ago using Sony Sound Forge (I just ripped the CD and saved each song as an mp3). And each song was categorized by the artist and uploaded to several albums with the same name. What’s worse two albums were slapped with some random thumbnails.

Incorrectly uploaded to multiple albums

Incorrectly uploaded to multiple albums

Here’s a simple tip that will only take about 5-10 minutes to fix the problem. The problem usually lies with incomplete ID-tags. What we see right away is there’s no track number information. And there are other missing information that we cannot see unless we check the Properties of the files.

Windows explorer showing MP3 songs collection with various artists

MP3 collection with incomplete ID-tags

So the first step we want to do is to highlight all the mp3 files you want to upload (left-click on the first song on the top and press shift and left-click on the last song at the very bottom of the list), then right-click your mouse on any of the song and go to Properties.

Find an ID-tag Property called Album artist and type in “Various Artists” without the quotes. You may also want to edit other metadata that are supposed to be the same for all mp3 files. Here you want to make sure you only edit all metadata for the group but not for the individual file. For example, in my case here, I already have the same Album name “Relaxing Classical” so I don’t need to update it, but you may see (multiple values) on your compilation for Album. If that’s the case, you want to update it using the same name. Click OK after you’re done.

Edit group metadata

Edit group metadata

Next, we need to do a rather tedious work, that is to pick each mp3 and assign a track number. If you don’t have that information, you can do search from Amazon or other search engines. I usually find most metadata and album artwork from Amazon.

Edit individual metadata (assign track number)

Edit individual metadata (assign track number)

When you’ve finished assigning track numbers, your mp3 collections should look similar to this. And you’re pretty much done.

MP3 files with assigned track numbers

MP3 files with assigned track numbers

Before you re-upload your mp3 to your Amazon Cloud Drive, you might want to delete all the botched uploads first just to clean your cloud space.

Now you’re album should show correctly.

Corrected MP3 album on Amazon Cloud Drive

Corrected MP3 album upload

* The artwork was added separately using dBpoweramp ID tag editor to all mp3 files before they were uploaded.

Hope it helps.


October 24, 2011 Filed Under: How To Tagged With: Amazon

« Previous Page
Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2026 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure