• Resolved ilyapokrov

    (@ilyapokrov)


    Please tell me how to write the new code correctly.

    There is such a parameter:
    <param name = "Gender"> Male, Female </param>

    To record both, I use:
    [str_replace (",", "|", {param [@ name = "Gender"]})]

    To change the parameter names like in my directory I use:
    [my_map_data ({param [@ name = "Gender"]})]

    function my_map_data ($ data) {
         $ map = array (
    'Male' => 'for men',
    'Female' => 'for women',
    
             'In this' => 'Array'
         );
         return (array_key_exists ($ data, $ map))? $ map [$ data]: $ data;
    }

    Question: What should be done and how to write the code, if you need to specify both the first and second codes?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @ilyapokrov,

    Question: What should be done and how to write the code, if you need to specify both the first and second codes?

    It’d be easiest to just add a new translation rule in the array, e.g.:

    'Male| Female' => 'for men|for women'

    Or, if you’re translating before changing the comma:

    'Male, Female' => 'for men|for women'

    Thread Starter ilyapokrov

    (@ilyapokrov)

    @wpallimport,
    Did I understand you correctly?

    For example, there are such parameters:

    <param name = "Gender"> Female </param>
    <param name = "Gender"> Male</param>
    <param name = "Gender"> Female, Male </param>
    <param name = "Gender"> Male, Female </param>
    <param name = "Gender"> Male, Female, Child </param>

    That is, I need to write and translate each value manually?
    [my_map_data ({param [@name="Gender"]})]

    function my_map_data ($ data) {
         $ map = array (
    'Male' => 'for men',
    'Female' => 'for women',
    'Female, Male' => 'for women|for men',
    'Male, Female' => 'for women|for men',
    'Male, Female, Child' => 'for women|for men|for children',
         );
         return (array_key_exists ($ data, $ map))? $ map [$ data]: $ data;
    }

    It happens that new parameter values appear. And if I have not specified them, then in the end I will get some kind of nonsense if I do not specify this parameter for translation.

    Plugin Author WP All Import

    (@wpallimport)

    Hey @ilyapokrov,

    It happens that new parameter values appear. And if I have not specified them, then in the end I will get some kind of nonsense if I do not specify this parameter for translation.

    In that case, it might be best to modify the “my_map_data” function so that it explode()‘s the gender values into an array, loops through each value and maps them individually, then implode()‘s the translated values and returns them to the import field.

    Thread Starter ilyapokrov

    (@ilyapokrov)

    @wpallimport,
    I am very sorry, but I did not understand anything =)))
    Can you show it with my example?

    Plugin Author WP All Import

    (@wpallimport)

    Hey @ilyapokrov,

    I’m sorry, but I don’t have an example snippet for this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Two functions in one’ is closed to new replies.