#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    3
    Rep Power
    0

    url rewriting (slugification)


    Dear devshed community,

    For my current assignment, I must rewrite url's (slugs).

    Now, because my php knowledge is very, very low, I'm kind-of in a messed up situation.

    Here is what my assignment is:


    This is what you have to do when you find a URL which is not translated

    1. Find in code where that url is outputted (the part which needs translation is usually a slug, created with the "urlrewrite"
    function/procedure)

    2. Once you've found that string/variable, you must assess if it has a translation

    3. Track down where that string/variable comes from, identify the database table, check if that table has translation
    (usually {name_of_the_original_table}_translation)

    4. Identify the initial point where the variable/string is coming from (usually a method on a model, which does the query)

    5. Join with the translations table on the relevant keys, and select the translation string as
    {name_of_the_original_field}_translation

    6. Output the translated string if exists, otherwise the original string.

    Now, I don't understand too much of this. To be honest this looks like rocket science to me.

    I can't accept a no as answer, I must get this assignment finished.

    Is there anyone who could help me out with this, every step (1 to 6)?

    Like, how do I find in the code (inspect source) where a url is outputted?


    Note: I'm a Java developer. I've got alot of experience with Java but none with php. this is why I accepted this job.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    3
    Rep Power
    0
    Oh and also, I'm really, like really interested in learning to code php. I really want this. I hope this will help me along my way to becoming a professional php programmer (back-end).
  4. #3
  5. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    It's quite hard to say what to do without knowing the site, codebase, system, architecture... Frankly, you're in a better position to understand what the directions are trying to get you to do, even if you don't quite understand exactly how to do it.


    1. Find in code where that url is outputted (the part which needs translation is usually a slug, created with the "urlrewrite"
    function/procedure)
    To do that you need to understand how the codebase is arranged. Where requests come into the site, what code handles the requests, and where the output ultimately comes from. It's hard to give advice for this at a general level because it can vary a lot.
    If you have no idea how it works then you can set up a debugger (a task in its own right) and watch the execution for the page. It'll take time to step through everything but you're guaranteed to eventually find where the output is.

    2. Once you've found that string/variable, you must assess if it has a translation
    Probably requires a minute of thought on your part.

    3. Track down where that string/variable comes from, identify the database table, check if that table has translation
    (usually {name_of_the_original_table}_translation)
    That means going backwards through the code to find where the value/string/variable/whatever gets its value. Apparently it will come from the database at some point, and apparently from a database table that might have a "translated" version.

    4. Identify the initial point where the variable/string is coming from (usually a method on a model, which does the query)
    This will probably happen before #3.

    5. Join with the translations table on the relevant keys, and select the translation string as
    {name_of_the_original_field}_translation
    There will be a database query at some point to get the value, and possibly other things. Or maybe the code will use a query building system. Either way, the query needs to be modified to JOIN in that translation table so that the original value (as it is now) and the translated value (if available) are both returned. Specifically you'll want an outer join (LEFT/RIGHT) in case the value doesn't have a translation.

    6. Output the translated string if exists, otherwise the original string.
    The new translated value needs to "bubble up" through the code just like the original value did. Then the code that does the output - what you found in steps #3 and #4 - gets an adjustment so it can show the translated value.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    3
    Rep Power
    0
    Woah, incredible reply. I'll get to work on this immediatly. Would it be possible for me to add you on skype for any future questions I might have?

IMN logo majestic logo threadwatch logo seochat tools logo